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

相关推荐
睡觉z20 分钟前
Jenkins持续集成系统
运维·ci/cd·jenkins
MANONGMN2 小时前
Kubernetes(K8s)常用命令全解析:从基础到进阶
云原生·容器·kubernetes
Wy_编程4 小时前
Linux文件相关命令
linux·运维
Viking_bird4 小时前
centos 7.5 + Hadoop 3.2.4 集群搭建
linux·运维·服务器·hadoop·centos
黑客影儿5 小时前
Kali Linux 环境中的系统配置文件与用户配置文件大全
linux·运维·程序人生·安全·网络安全·系统安全·学习方法
岚天start5 小时前
Linux系统网络排查工具总结
linux·运维·网络·监控·扫描·连通性·流量
Lovyk7 小时前
基于 Ansible 与 Jinja2 模板的 LNMP 环境及 WordPress 自动化部署实践
linux·运维·服务器·自动化·ansible
知白守黑2677 小时前
Linux磁盘阵列
linux·运维·服务器
维尔切9 小时前
Linux中基于Centos7使用lamp架构搭建个人论坛(wordpress)
linux·运维·架构
__lll_9 小时前
手把手教你用 Docker 部署 Vue 项目(含国内镜像加速 + 踩坑指南)
docker