Linux安装docker

卸载旧版本的docker

1
yum remove docker-ce docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine

使用yum命令安装docker

1
yum install -y yum-utils device-mapper-persistent-data lvm2

设置yum镜像源

1
2
3
yum-config-manager --add-repo http://download.docker.com/linux/centos/docker-ce.repo

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

安装最新版本的 Docker Engine-Community 和 containerd

1
yum -y install docker-ce docker-ce-cli containerd.io

查看安装版本,验证是否安装成功

1
docker -v

查看安装路径

1
sudo docker info | grep "Docker Root Dir"

修改安装路径

此步骤为非必要步骤

1
2
3
4
5
6
7
8
9
10
11
12
# 停止docker
systemctl stop docker.socket
systemctl stop docker

# 移动docker所有文件
mv /var/lib/docker /home/docker

# 建立软连接
ln -s /home/docker /var/lib/docker

# 重启docker
systemctl restart docker

启动docker,并设置docker开机自启

1
2
3
4
5
6
7
8
9
10
systemctl start docker
systemctl enable docker

#停止docker
systemctl stop docker
#重启docker
systemctl restart docker

#查看状态
systemctl status docker

设置docker的镜像环境

编辑配置文件
1
vim /etc/docker/daemon.json
追加配置
1
2
3
4
5
6
7
8
{
"registry-mirrors": [
"https://docker.m.daocloud.io",
"https://dockerproxy.com",
"https://docker.mirrors.ustc.edu.cn",
"https://docker.nju.edu.cn"
]
}
刷新配置并重启
1
2
systemctl daemon-reload
systemctl restart docker
查看是否更改成功
1
docker info

卸载docker

1
2
3
sudo yum remove docker-ce docker-ce-cli containerd.io
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd