docker正确配置腾讯云镜像地址

说明

腾讯软件源官网给的配置教程有误,配置完成之后还是显示无法连接,切换了一下方式才成功,记录一下。

官网文档

附上官网文档地址:腾讯云修改docker镜像文档

附上腾讯云软件源官网:腾讯软件源

下面是详细步骤,Ubuntu系统:

1
2
3
4
5
6
7
8
9
# 打开配置文件

vim /etc/default/docker



# 添加以下内容

DOCKER_OPTS="--registry-mirror=https://mirror.ccs.tencentyun.com"

CentOS7系统:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# 打开配置文件

vim /etc/docker/daemon.json



# 添加以下内容

{

   "registry-mirrors": [

   "https://mirror.ccs.tencentyun.com"

  ]

}

修改完配置文件,重启一下docker

1
2
3
systemctl daemon-reload

systemctl restart docker

验证

执行

1
docker info

输出的内容最后三行有这个就表示配置成功:

1
2
3
4
5
 Registry Mirrors:

  https://mirror.ccs.tencentyun.com/

 Live Restore Enabled: false

补充

我的系统是Ubuntu22.04,但是按照Ubuntu系统那样配置没生效,而且,那个配置文件默认是有内容的,只需要把注释符号删掉修改一下就可以了,即第14行,原始内容如下:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Docker SysVinit configuration file



#

# THIS FILE DOES NOT APPLY TO SYSTEMD

#

#   Please see the documentation for "systemd drop-ins":

#   https://docs.docker.com/engine/admin/systemd/

#



# Customize location of Docker binary (especially for development testing).

#DOCKERD="/usr/local/bin/dockerd"



# Use DOCKER_OPTS to modify the daemon startup options.

#DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4"



# If you need Docker to use an HTTP proxy, it can also be specified here.

#export http_proxy="http://127.0.0.1:3128/"



# This is also a handy place to tweak where Docker's temporary files go.

#export DOCKER_TMPDIR="/mnt/bigdrive/docker-tmp"

但我换成CentOS那样的配置文件就生效了,所以我查看了一下上面文件里的docker官方文档,文档显示,这个文件是配置docker守护进程的,需要添加一个守护进程,而守护进程使用的配置文件就是这个/etc/docker/daemon.json,所以腾讯云的文档不太严谨,可能是没有更新,官网写的docker23.0以上都是这样。以后还是建议查看docker官网文档。配置守护进程验证如下:

1
2
3
4
5
sudo systemctl show --property=Environment docker



Environment=HTTP_PROXY=http://proxy.example.com:3128 HTTPS_PROXY=https://proxy.example.com:3129 NO_PROXY=localhost,127.0.0.1,docker-registry.example.com,.corp

相应的配置文件如下:

1
2
3
4
5
6
7
[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"

文件路径为:/etc/systemd/system/docker.service.d/http-proxy.conf

使用 Hugo 构建
主题 StackJimmy 设计