【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 ***来安装所需库

相关推荐
深爱水瓶 血影S狂风4 小时前
函数调用过程探究
linux·运维·服务器
酷可达拉斯4 小时前
Linux操作系统-磁盘空间使用率100%如何处理?
linux·运维·服务器·云计算·bash
yuezhilangniao4 小时前
AI工具全家桶:从开发到运维,从数据库到产品经理-含魔塔社区简介
运维·数据库·人工智能
兵bing5 小时前
Docker Compose 进阶配置与最佳实践笔记
docker
xiaoxiangsiyan5 小时前
LNMP + Redis Sentinel 高可用架构部署手册(续)
运维·网络·数据库·redis·缓存·架构·sentinel
是良辰5 小时前
Docker Nginx HTTPS 自签证书部署完整操作文档
nginx·docker·https
BullSmall5 小时前
scanoss-engine 本地最简部署 & 扫描命令(Linux/Anolis OS)
linux·运维·服务器
陈聪.5 小时前
Keepalived 高可用集群:从原理到企业级实践
运维
bellus-6 小时前
Ubuntu 26.04 Miniforge3 安装与配置完整指南
linux·运维·ubuntu
575776 小时前
户外净水器过滤效果怎么看:对照孔径、除菌率和认证三项再下单
运维·服务器