1. 安装docker-ce
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum -y install docker-ce
sudo systemctl enable docker
2. 设置代理
参照:https://docs.docker.com/config/daemon/systemd/#httphttps-proxy
1) sudo mkdir -p /etc/systemd/system/docker.service.d
2) 创建一个新文件:
/etc/systemd/system/docker.service.d/http-proxy.conf
并在里面配置:
[Service]
Environment="HTTP_PROXY=http://your_ip:port"
Environment="HTTPS_PROXY=http://your_ip:port"
如果某些registry希望绕过代理,那么可以配置NO_PROXY,比如:
[Service]
Environment="HTTP_PROXY=http://proxy.example.com:3128"
Environment="HTTPS_PROXY=https://proxy.example.com:3129"
Environment="NO_PROXY=localhost,127.0.0.1,docker-registry.example.com,.corp"
3) 设置完以后执行:
sudo systemctl daemon-reload
sudo systemctl restart docker
通过docker info可以查看是否已经生效
3. 配置国内Docker镜像源
1) 查找镜像,如果有阿里云账号,那么:https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors
里面可以看到如下内容中的registry-mirrors:
其他镜像:
Docker中国区官方镜像
https://registry.docker-cn.com
网易
http://hub-mirror.c.163.com
ustc
https://docker.mirrors.ustc.edu.cn
2) 修改配置文件/etc/docker/daemon.json,如果没有就创建一个:
{
"log-level": "debug",
"registry-mirrors": ["https://xxxxhr.mirror.aliyuncs.com", "https://docker.mirrors.ustc.edu.cn"]
}
3) 设置完以后执行:
sudo systemctl daemon-reload
sudo systemctl restart docker
通过docker info可以查看是否已经生效
4. build image 设置代理
修改docker file, 设置HTTP_PROXY与HTTPS_PROXY, 比如:
#
FROM python:3.9
# 设置代理
ENV HTTP_PROXY=http://x.x.x.x:8080
ENV HTTPS_PROXY=http://x.x.x.x:8080
#
WORKDIR /code
#
COPY ./requirements.txt /code/requirements.txt
#
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
#
COPY ./app /code/app
#
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8090"]
然后可以执行docker build