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

相关推荐
郭老二7 分钟前
【docker】docker compose使用,已nginx为例
nginx·docker·容器
寻道模式38 分钟前
【运维心得】完整教程:绕过Win11限制让老机焕发新生
运维·操作系统·win11
zzu123zsw42 分钟前
从 proxy_pass 末尾斜杠到 WebAssembly 预压缩:深挖 Nginx 生产环境四大高频踩坑点
运维·nginx·wasm·webassembly·devops·运维排错
张洛闻Eren1 小时前
Ansible【第一课】:Ansible介绍
运维·数据库·云原生·kubernetes·github·ansible
郝亚军2 小时前
RK3562 中有 mosquitto、nginx 了,还需要 http,ftp,tftp 等协议吗?
运维·nginx·http
a5986522 小时前
Docker云手机端口不通,无法访问|六边云手机教你故障排查完整流程
docker·容器·性能优化·云手机
杰克尼2 小时前
Kubernetes
云原生·容器·kubernetes
重生之小比特2 小时前
【Linux系统】07 进程状态
linux·运维·服务器
敲代码的彭于晏2 小时前
2026 K8s 零基础入门:手把手教你一步步搭建 Kubernetes 集群
java·运维·全栈
ManageEngine卓豪3 小时前
智能运维如何降低 MTTR:告警聚类、因果分析与自动化修复的工程拆解
运维·智能运维·mttr