井底圈小蛙
关注科技圈

Centos7 安装Docker-ce以及修改Docker的默认数据存储目录

Centos7自带的Docker版本太低,必须通过源进行安装,安装后一般默认数据存储目录是/var/lib/docker,但是Docker需要的存储目录都会很大,因此需要修改存储路径。

一、卸载默认安装(yum install docker)的Docker,用yum彻底移除

yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-selinux \
                  docker-engine-selinux \
                  docker-engine

二、添加高版本的Docker源,安装高版本Docker

vim /etc/yum.repos.d/CentOS-Docker-ce.repo
[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://download.docker.com/linux/centos/7/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg

[docker-ce-stable-debuginfo]
name=Docker CE Stable - Debuginfo $basearch
baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/stable
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg

[docker-ce-stable-source]
name=Docker CE Stable - Sources
baseurl=https://download.docker.com/linux/centos/7/source/stable
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg

[docker-ce-edge]
name=Docker CE Edge - $basearch
baseurl=https://download.docker.com/linux/centos/7/$basearch/edge
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg

[docker-ce-edge-debuginfo]
name=Docker CE Edge - Debuginfo $basearch
baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/edge
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg

[docker-ce-edge-source]
name=Docker CE Edge - Sources
baseurl=https://download.docker.com/linux/centos/7/source/edge
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg

[docker-ce-test]
name=Docker CE Test - $basearch
baseurl=https://download.docker.com/linux/centos/7/$basearch/test
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg

[docker-ce-test-debuginfo]
name=Docker CE Test - Debuginfo $basearch
baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/test
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg

[docker-ce-test-source]
name=Docker CE Test - Sources
baseurl=https://download.docker.com/linux/centos/7/source/test
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg

[docker-ce-nightly]
name=Docker CE Nightly - $basearch
baseurl=https://download.docker.com/linux/centos/7/$basearch/nightly
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg

[docker-ce-nightly-debuginfo]
name=Docker CE Nightly - Debuginfo $basearch
baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/nightly
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg

[docker-ce-nightly-source]
name=Docker CE Nightly - Sources
baseurl=https://download.docker.com/linux/centos/7/source/nightly
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
yum clean all
yum makecache
yum install -y docker-ce
systemctl start docker
systemctl enable docker
docker info

三、修改Docker的默认数据存储目录

方法一,修改配置文件

vim /etc/docker/daemon.json
{
 "data-root": "/data/docker"
}

方法二,创建软链接

# 停止docker服务
systemctl stop docker
# 创建目的存储路径
mkdir /data/docker
# 将原存储目录的文件转移至新目录
mv /var/lib/docker/* /data/docker
# 删除原目录
rm -rf /var/lib/docker
# 创建软链接
ln -s /data/docker /var/lib/docker
# 再启动docker服务
systemctl start docker

方法三,修改docker.service(适用于v17.05.0之前版本)

编辑文件 /usr/lib/systemd/system/docker.service

添加红色内容:ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --data-root=/data/docker

圈小蛙现已开通Telegram。单击此处加入我们的频道 (@quanxiaowa)并随时了解最新科技圈动态!

除特别注明外,本站所有文章均系根据各大境内外消息渠道原创,转载请注明出处。
文章名称:《Centos7 安装Docker-ce以及修改Docker的默认数据存储目录》
文章链接:https://www.qxwa.com/centos7-installation-of-docker-ce-and-modification-of-dockers-default-data-storage-directory.html
分享到: 生成海报

评论 抢沙发

科技圈动态,尽在圈小蛙

联系我们关注我们