使用阿里云对docker拉取镜像加速及开启ipv4转发
使用docker的时候,总是需要去search镜像,使用国外的源下载太慢,还有诸多的限制,无意中发现可以使用阿里云进行加速,实测有用,废话少说,操作如下:
1.打开阿里云控制台,没有的可以用淘宝账号或者支付宝账号直接登录
https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors
打开容器镜像服务,镜像加速器,复制加速地址后,按照第二个红框所示,完成配置。
2.重启docker
systemctl daemon-reload
systemctl restart docker
OK!加速完成,嗖嗖嗖!!!
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://c8it25aj.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload && systemctl restart docker
发现一个小bug: 修改daemon.json文件导致docker不能启动
网上大部分说是daemon.json的文件配置的有问题,有的说是docker软件包的问题,可实际上是没有问题的,最后通过修改/usr/lib/systemd/system/docker.service文件来解决了
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
# docker-18.03
ExecStart=/usr/bin/dockerd --data-root=/data/docker 删除掉这里的地址,这里会导致源与ali源冲突
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
"/usr/lib/systemd/system/docker.service" 36L, 1183C
使用docker需要开启ipv4转发:
装完了Docker,然后启动镜像,发现没有网络,而且不能ifconfig,因网桥配置完后,需要开启转发,不然容器启动后,就会没有网络,配置/etc/sysctl.conf,添加net.ipv4.ip_forward=1即可,操作如下:
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf && systemctl restart network
#查看是否成功,如果返回为“net.ipv4.ip_forward = 1”则表示成功
sysctl net.ipv4.ip_forward