![a788b2b1443ace8d1a5fccb27afefbd4.png](https://i-blog.csdnimg.cn/blog_migrate/101c6bc16fb7bf225edc3ccecc007907.jpeg)
资源:服务器为CentOS 7
使用yum 安装
查看服务器内核,Docker 运行在 CentOS 7 上,要求系统为64位、系统内核版本为 3.10 以上。
[root@iZ25ydqcv8uZ opt]# uname -a
Linux iZ25ydqcv8uZ 3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
删除旧版本
yum remove docker
docker-client
docker-client-latest
docker-common
docker-latest
docker-latest-logrotate
docker-logrotate
docker-selinux
docker-engine-selinux
docker-engine
yum 包更新到最新
yum update
安装一些必要的系统工具:
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 缓存:
yum makecache fast
安装 Docker-ce:
yum -y install docker-ce
启动 Docker 后台服务:
systemctl start docker
测试运行 hello-world:
docker run hello-world
设置重启自动启docker
systemctl enable docker.service
设置docker目录挂载
# 1、停止docker服务
systemctl stop docker 或 service docker stop
# 2、在磁盘空间较大或者挂载目录上,新建目录
mkdir –p /opt/docker
# 3、备份docker默认存储目录/var/lib/docker下的数据
cp –r /var/lib/docker/ /var/lib/docker_bak/
# 4、移动默认存储目录/var/lib/docker下的数据到新创建的目录/opt/docker上
mv /var/lib/docker /opt/docker/
# 5、创建软链接
ln -s /opt/docker/ /var/lib/docker
# 6、重启docker ,并观察磁盘空间及目录
systemctl start docker
df -h