Docker容器内apt-get更换国内源

2021-01-10  本文已影响0人  山哥的哥

环境

docker ps
CONTAINER ID   IMAGE                           COMMAND                  CREATED        STATUS        PORTS                NAMES
636aa46e986a   nginx                           "/docker-entrypoint.…"   20 hours ago   Up 20 hours   0.0.0.0:80->80/tcp   dev-nginx
9d904727fd88   php:5.6-fpm                     "docker-php-entrypoi…"   20 hours ago   Up 20 hours   9000/tcp             php56fpm

打开一个容器的终端

docker exec -it php56fpm /bin/bash

以下均在容器的终端里操作

备份

cp /etc/apt/sources.list /etc/apt/sources.list.bak

写入国内源

echo 'deb http://mirrors.163.com/debian/ stretch main non-free contrib' > /etc/apt/sources.list
echo 'deb http://mirrors.163.com/debian/ stretch-updates main non-free contrib' >> /etc/apt/sources.list
echo 'deb http://mirrors.163.com/debian-security/ stretch/updates main non-free contrib' >> /etc/apt/sources.list

更新

apt-get update

安装示例

apt-get install libssl-dev

感受一下速度吧

Alpine apk国内仓库

进入容器后运行以下命令

sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories

然后更新

apk update
上一篇下一篇

猜你喜欢

热点阅读