二、Docker 镜像源加速地址修改和Docker应用全局HTT

2022-03-16  本文已影响0人  CoderMichael

1、 Docker 镜像源加速地址修改

环境

从网上找了几个速度比较快的镜像加速地址:

1. Docker 官方中国区
https://registry.docker-cn.com
2. 网易
http://hub-mirror.c.163.com
3. ustc
https://docker.mirrors.ustc.edu.cn

修改方法

docker run hello-world --registry-mirror=https://docker.mirrors.ustc.edu.cn
DOCKER_OPTS="--registry-mirror=https://docker.mirrors.ustc.edu.cn"
[Service] 
ExecStart= 
ExecStart=/usr/bin/docker -d -H fd:// --registry-mirror=https://docker.mirrors.ustc.edu.cn
{ 
"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 DaemonDocker Engine,不同版本会有差异。编辑窗口内的JSON串,填写下方加速器地址:

"registry-mirrors": ["https://3v68smwd.mirror.aliyuncs.com"]
image.png

编辑完成后点击 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.

  1. Create a systemd drop-in directory for the docker service:
$ sudo mkdir -p /etc/systemd/system/docker.service.d
  1. 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/"
  1. 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"
  1. Flush changes:
$ sudo systemctl daemon-reload
  1. Restart Docker:
$ sudo systemctl restart docker
  1. 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/

参考:

上一篇 下一篇

猜你喜欢

热点阅读