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

相关推荐
waves浪游1 天前
Linux基本指令(下)
linux·运维·服务器
2401_831501731 天前
Linux之lvm存储卷管理篇
运维
The Future is mine1 天前
.Net Core 在Linux系统下创建服务
linux·运维·.netcore
一只积极向上的小咸鱼1 天前
Windows中通过wsl运行Ubuntu
linux·运维·ubuntu
小杨的全栈之路1 天前
生产级实践:在 Docker 中安全导入自签名证书,保障 Spring Boot 应用通信安全
docker·https
爱吃汽的小橘1 天前
异步串口通信和逻辑分析仪
运维·服务器·网络·单片机·嵌入式硬件·fpga开发
静谧之心1 天前
在 K8s 上可靠运行 PD 分离推理:RBG 的设计与实现
云原生·容器·golang·kubernetes·开源·pd分离
Maple_land1 天前
Linux进程第八讲——进程状态全景解析(二):从阻塞到消亡的完整生命周期
linux·运维·服务器·c++·centos
爱吃生蚝的于勒1 天前
【Linux】零基础学会Linux之权限
linux·运维·服务器·数据结构·git·算法·github
Cyan_RA91 天前
Linux 远程Ubuntu服务器本地部署大模型 EmoLLM 中常见的问题及解决方案 万字详解
linux·运维·服务器·ubuntu·大模型·远程部署·emollm