【docker】容器无法使用vi等命令,无法联网,无法换源如何解决?

解决方案:

在宿主机某个位置上创建文件: sources.list

然后修改文件,写入清华源

bash 复制代码
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse

# deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
# # deb-src http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse

执行 docker ps查询容器名;

在这个sources.list所在位置打开命令行。执行以下命令,将宿主机的sources.list拷贝到容器中

bash 复制代码
docker cp sources.list 容器名:/etc/apt

然后进入容器里面再更新源

bash 复制代码
docker exec -it 容器名 /bin/bash
...
apt-get update

等更新完后,可以sudo apt install ***来安装所需库

相关推荐
哲Zheᗜe༘18 分钟前
学习K8S-Deployment资源对象
docker·容器·kubernetes
生活爱好者!22 分钟前
【影视项目】NAS 部署稳定视频订阅源咪咕
服务器·网络·docker·容器·音视频
骥龙31 分钟前
5.14、AI安全运维体系:构建企业级的“安全超脑”
运维·人工智能·安全
源梦想34 分钟前
机甲恐龙动作冒险网页小游戏Linux部署教程
linux·运维·服务器
该用户已不存在41 分钟前
Let’s Encrypt 证书有效期将缩至 45 天,运维天都塌了
运维·https·自动化运维
robin591144 分钟前
容器-PUSH镜像卡住问题排查
容器·golang·kubernetes
yiyeguzhou1001 小时前
论文解读:Overcoming the IOTLB wall for multi-100-Gbps Linux-based networking
linux·运维·服务器
国家不保护废物1 小时前
RAG + Agent + Prompt工程中
docker·llm·aigc
妄想出头的工业炼药师1 小时前
cuda如何安装卸载
linux·运维·服务器
泡沫·1 小时前
3.sed 使用手册
运维