1、 Docker 镜像源加速地址修改
环境
- Docker 版本为: Docker version 17.03.2-ce, build f5ec1e2
- 宿主机为: CentOS7
从网上找了几个速度比较快的镜像加速地址:
1. Docker 官方中国区
https://registry.docker-cn.com
2. 网易
http://hub-mirror.c.163.com
3. ustc
https://docker.mirrors.ustc.edu.cn
修改方法
- 直接设置 –registry-mirror 参数,仅对当前的命令有效
docker run hello-world --registry-mirror=https://docker.mirrors.ustc.edu.cn
- 修改 /etc/default/docker,加入 DOCKER_OPTS=”镜像地址”,可以有多个
DOCKER_OPTS="--registry-mirror=https://docker.mirrors.ustc.edu.cn"
- 支持 systemctl 的系统,通过 sudo systemctl edit docker.service,会生成 /etc/systemd/system/docker.service.d/override.conf 覆盖默认的参数,在该文件中加入如下内容:
[Service]
ExecStart=
ExecStart=/usr/bin/docker -d -H fd:// --registry-mirror=https://docker.mirrors.ustc.edu.cn
- 新版的 Docker 推荐使用 json 配置文件的方式,默认为
/etc/docker/daemon.json
,非默认路径需要修改 dockerd 的 –config-file,在该文件中加入如下内容:
{
"registry-mirrors": ["http://hub-mirror.c.163.com"]
}
我采用修改
/etc/docker/daemon.json
文件的方式,可以使用阿里云或网易的镜像加速,以下是我的配置内容:
{
"registry-mirrors": ["https://3v68smwd.mirror.aliyuncs.com","http://hub-mirror.c.163.com"]
}
补充:针对Windows10 系统,安装了Docker for Windows的用户,您可以参考以下配置步骤:
在系统右下角托盘图标内右键菜单选择 Settings,打开配置窗口后左侧导航菜单选择 Docker Daemon
或 Docker Engine
,不同版本会有差异。编辑窗口内的JSON串,填写下方加速器地址:
"registry-mirrors": ["https://3v68smwd.mirror.aliyuncs.com"]
编辑完成后点击 Apply 保存按钮,等待Docker重启并应用配置的镜像加速器。
2、 Docker应用全局HTTP Proxy配置
If you are behind an HTTP or HTTPS proxy server, for example in corporate settings, you need to add this configuration in the Docker systemd service file.
- Create a systemd drop-in directory for the docker service:
$ sudo mkdir -p /etc/systemd/system/docker.service.d
- Create a file called
/etc/systemd/system/docker.service.d/http-proxy.conf
that adds the HTTP_PROXY environment variable:
[Service]
Environment="HTTP_PROXY=http://proxy.example.com:80/"
Or, if you are behind an HTTPS proxy server, create a file called /etc/systemd/system/docker.service.d/https-proxy.conf that adds the HTTPS_PROXY environment variable:
[Service]
Environment="HTTPS_PROXY=https://proxy.example.com:443/"
- If you have internal Docker registries that you need to contact without proxying you can specify them via the NO_PROXY environment variable:
[Service]
Environment="HTTP_PROXY=http://proxy.example.com:80/" "NO_PROXY=localhost,127.0.0.1,docker-registry.somecorporation.com"
Or, if you are behind an HTTPS proxy server:
[Service]
Environment="HTTPS_PROXY=https://proxy.example.com:443/" "NO_PROXY=localhost,127.0.0.1,docker-registry.somecorporation.com"
我采用创建
/etc/systemd/system/docker.service.d/http-proxy.conf
文件的方式,并按如下方式配置:
[Service]
Environment="HTTPS_PROXY=http://192.168.1.100:1080/" "HTTP_PROXY=http://192.168.1.100:1080/" "NO_PROXY=localhost,127.0.0.1"
- Flush changes:
$ sudo systemctl daemon-reload
- Restart Docker:
$ sudo systemctl restart docker
- Verify that the configuration has been loaded:
$ systemctl show --property=Environment docker
Environment=HTTP_PROXY=http://proxy.example.com:80/
Or, if you are behind an HTTPS proxy server:
$ systemctl show --property=Environment docker
Environment=HTTPS_PROXY=https://proxy.example.com:443/