1. docker代理设置
  2. docker镜像加速

docker代理设置

docker代理设置分为两类:

  1. 镜像的代理设置
  2. build代理设置

镜像的代理设置

  1. 默认情况下这个配置文件夹并不存在,创建配置文件夹。
1
mkdir -p /etc/systemd/system/docker.service.d
  1. 创建文件/etc/systemd/system/docker.service.d/http-proxy.conf,包含有HTTP_PROXY环境变量
1
2
3
4
[Service]
Environment="HTTP_PROXY=http://proxy.example.com:80/"
Environment="HTTPS_PROXY=https://proxy.example.com:80/"
Environment="NO_PROXY=localhost,127.0.0.1,daocloud.io"
  1. 刷新systemd配置:
1
sudo systemctl daemon-reload
  1. 用系统命令验证环境变量:
1
systemctl show --property=Environment docker
  1. 重启docker
1
sudo systemctl restart docker 

ubuntu dockerfile build apt-get代理设置

  1. 新建文件 apt.conf, 文件内容如下:
1
2
3
Acquire::http::proxy "http://127.0.0.1:8080/";
Acquire::https::proxy "http://127.0.0.1:8080/";

  1. RUN apt-get 命令前加上 COPY apt.conf /etc/apt/apt.conf

其他系统的类似,遇到再添加

镜像加速

MacOS 设置

右键点击桌面顶栏的 docker 图标,选择 Preferences ,在 Daemon 标签(Docker 17.03 之前版本为 Advanced 标签)下的 Registry mirrors 列表中加入下面的镜像地址:

1
http://f1361db2.m.daocloud.io

点击 Apply & Restart 按钮使设置生效。