使用阿里镜像安装docker
-
如果安装过docker先卸载
yum remove docker docker-common docker-selinux docker-engine -y -
yum install -y yum-utils device-mapper-persistent-data lvm2
-
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
-
yum makecache fast
-
yum install docker-ce -y
-
docker version 报错:Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
解决办法systemctl daemon-reload sudo service docker restart sudo service docker status
设置开机自启动 systemctl enable docker.service
将docker的仓库改为aliyun的镜像仓库
-
使用命令 vi /etc/docker/daemon.json添加如下
{ "registry-mirrors": ["https://xx.mirror.aliyuncs.com"] }
sudo systemctl daemon-reload
sudo systemctl restart docker
开启远程
- vim /lib/systemd/system/docker.service(修改最好做个备份)
- 修改ExecStart行为下面内容
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375
使用这种方式成功ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
使用这种方式重启失败
- systemctl daemon-reload
- systemctl restart docker
- 防火墙设置 使用时暂时开启2375端口
使用后重启服务,使规则失效iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT iptables -I INPUT -p tcp --dport 2375 -j ACCEPT
service iptables restart
常见问题
- 如果更改iptabels需要重启docker, service docker restart 否则外网不能访问映射端口