以centos7.*为例

1
2
3
4
5
6
7
8
#更新yum包
yum update -y
#下载docker
yum intall -y docker
#启动docker
systemctl start docker
#开机自启docker
systemctl enable docker

如果运行容器的时候忘记设置开机自启就可以执行下面

1
docker update --restart=always 容器名或者ID

和容器同用网络

1
--net=host

换阿里云源

1
vi /etc/docker/daemon.json
1
{"registry-mirrors": ["https://pee6w651.mirror.aliyuncs.com"]}

安装docker-compose

1
2
sudo curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose