背景说明
一般情况下,安装完docker之后可以正常启动Docker相关服务,但是当需要获取镜像时,由于默认的镜像仓库在国外,由于墙的原因,镜像下载的速度慢且不稳定,于是,我们可以将仓库改成国内的,比如阿里提供的镜像加速。
每个阿里云账号有自己的专属的加速器地址
解决方案
网页直链
https://cr.console.aliyun.com/#/accelerator
加速地址
浏览器访问地址:https://www.aliyun.com/product/acr
选择容器镜像服务ACR
选择管理控制台
配置方案
启动参数
状态查看
[root@vm system]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2020-02-10 17:37:29 CST; 1h 59min ago
Docs: https://docs.docker.com
Main PID: 15256 (dockerd)
CGroup: /system.slice/docker.service
└─15256 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Feb 10 17:37:29 vm dockerd[15256]: time="2020-02-10T17:37:29.052785177+08:00" level=info msg="ClientConn switchin...e=grpc
Feb 10 17:37:29 vm dockerd[15256]: time="2020-02-10T17:37:29.062543996+08:00" level=info msg="Loading containers: start."
Feb 10 17:37:29 vm dockerd[15256]: time="2020-02-10T17:37:29.592241301+08:00" level=info msg="Default bridge (doc...dress"
Feb 10 17:37:29 vm dockerd[15256]: time="2020-02-10T17:37:29.820389366+08:00" level=info msg="Loading containers: done."
Feb 10 17:37:29 vm dockerd[15256]: time="2020-02-10T17:37:29.851582816+08:00" level=warning msg="Not using native...erlay2
Feb 10 17:37:29 vm dockerd[15256]: time="2020-02-10T17:37:29.851862707+08:00" level=info msg="Docker daemon" comm...9.03.5
Feb 10 17:37:29 vm dockerd[15256]: time="2020-02-10T17:37:29.851924932+08:00" level=info msg="Daemon has complete...ation"
Feb 10 17:37:29 vm dockerd[15256]: time="2020-02-10T17:37:29.972226271+08:00" level=info msg="API listen on /var/....sock"
Feb 10 17:37:29 vm systemd[1]: Started Docker Application Container Engine.
Feb 10 19:35:53 vm systemd[1]: [/usr/lib/systemd/system/docker.service:38] Unknown lvalue 'TasksMax' in section 'Service'
Hint: Some lines were ellipsized, use -l to show in full.
编辑配置
进入路径/lib/systemd/system
编辑docker.service
配置文件,然后找到ExecStart这项,将阿里云的加速器地址拷贝到截图这个地方。
[root@vm system]# cd /lib/systemd/system
[root@vm system]# ls -l |grep docker.service
-rw-r--r--. 1 root root 1683 Nov 13 15:25 docker.service
[root@vm system]# vim docker.service
9 [Service]
10 Type=notify
11 # the default is not to use systemd for cgroups because the delegate issues still
12 # exists and systemd currently does not support the cgroup feature set required
13 # for containers run by docker
14 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
15 ExecReload=/bin/kill -s HUP $MAINPID
16 TimeoutSec=0
17 RestartSec=2
18 Restart=always
编辑ExecStart
属性值
ExecStart=/usr/bin/dockerd --registry-mirror https://b7j3uwrc.mirror.aliyuncs.com -H fd:// --containerd=/run/containerd/containerd.sock
私有仓库[—insecure-registry 172.31.98.241:8082 ] 注意:配置需要添加在
-H
之前否则不生效
加载配置
配置好文件后重载配置文件
[root@vm system]# systemctl daemon-reload
重启服务
启动docker
[root@vm system]# systemctl restart docker
查看状态
[root@vm system]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2020-02-10 19:40:45 CST; 5s ago
Docs: https://docs.docker.com
Main PID: 50570 (dockerd)
Memory: 44.0M
CGroup: /system.slice/docker.service
└─50570 /usr/bin/dockerd --registry-mirror=https://b7j3uwrc.mirror.aliyuncs.com -H fd:// --containerd=/run/containerd/containerd.sock
Feb 10 19:40:44 vm dockerd[50570]: time="2020-02-10T19:40:44.451512387+08:00" level=info msg="ClientConn switching balancer to \"pick_first\"" module=grpc
Feb 10 19:40:44 vm dockerd[50570]: time="2020-02-10T19:40:44.459093097+08:00" level=info msg="[graphdriver] using prior storage driver: overlay2"
Feb 10 19:40:44 vm dockerd[50570]: time="2020-02-10T19:40:44.474401723+08:00" level=info msg="Loading containers: start."
Feb 10 19:40:45 vm dockerd[50570]: time="2020-02-10T19:40:45.009310553+08:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0...IP address"
Feb 10 19:40:45 vm dockerd[50570]: time="2020-02-10T19:40:45.241392858+08:00" level=info msg="Loading containers: done."
Feb 10 19:40:45 vm dockerd[50570]: time="2020-02-10T19:40:45.276477408+08:00" level=warning msg="Not using native diff for overlay2, this may cause degraded p...er=overlay2
Feb 10 19:40:45 vm dockerd[50570]: time="2020-02-10T19:40:45.276797901+08:00" level=info msg="Docker daemon" commit=633a0ea graphdriver(s)=overlay2 version=19.03.5
Feb 10 19:40:45 vm dockerd[50570]: time="2020-02-10T19:40:45.276857654+08:00" level=info msg="Daemon has completed initialization"
Feb 10 19:40:45 vm dockerd[50570]: time="2020-02-10T19:40:45.306857874+08:00" level=info msg="API listen on /var/run/docker.sock"
Feb 10 19:40:45 vm systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.
拉取镜像
[root@vm system]# docker pull primetoninc/jdk:1.8
1.8: Pulling from primetoninc/jdk
af4b0a2388c6: Pulling fs layer
配置文件
进入目录/etc/docker/
查看配置文件daemon.json
,如果不存在则创建
[root@template-docker ~]# mkdir /etc/docker
[root@template-docker ~]# touch /etc/docker/daemon.json
[root@vm ~]# cd /etc/docker/
Docker服务未启动时,目录/etc/docker不存在需要手动创建
编辑配置
[root@vm docker]# echo '{"registry-mirrors": ["https://b7j3uwrc.mirror.aliyuncs.com"]}' >> /etc/docker/daemon.json
[root@vm docker]# cat daemon.json
{"registry-mirrors": ["https://b7j3uwrc.mirror.aliyuncs.com"]}
[root@vm docker]#
加载配置
配置好文件后重载配置文件
[root@vm system]# systemctl daemon-reload
重启服务
启动docker
[root@vm system]# systemctl restart docker
配置查看
[root@vm system]# docker info
Client:
Debug Mode: false
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 19.03.5
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: b34a5c8af56e510852c35414db4c1f4fa6172339
runc version: 3e425f80a8c931f88e6d94a8c831b9d5aa481657
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-514.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 7.624GiB
Name: vm
ID: WPPJ:5XPD:QSPF:UAXC:7LWX:YHDO:3VCC:3WP2:55SY:E2SC:L4PT:CQPO
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Registry Mirrors:
https://b7j3uwrc.mirror.aliyuncs.com/
Live Restore Enabled: false
[root@vm system]#
拉取镜像
[root@vm system]# docker pull primetoninc/jdk:1.8
1.8: Pulling from primetoninc/jdk
af4b0a2388c6: Pulling fs layer