修改Docker数据目录位置,包含镜像位置

docker安装后,默认的下载位置是/var/lib/docker。如果/var分区没有独立分出来,linux系统的默认设置是与根分区/在一起。通常情况下,除非是配置邮件服务器,我们在安装linux系统时不会单独划分/var分区,而根分区的空间通常不会很大,例如我的根分区只有50gb。在拉取镜像时,可能会遇到硬盘空间不足的问题,而其他分区可能还有大量可用空间。基于这种情况,我们需要更改docker的数据目录位置。

首先,我们可以通过查看当前Docker的配置信息来确认Docker的数据目录位置:

# 展示当前Docker的配置信息 docker info # 在信息中找到Docker Root Dir,对应的就是数据目录,默认为: # Docker Root Dir: /var/lib/docker

修改Docker数据目录位置,包含镜像位置

有几种方法可以修改Docker的数据目录位置:

  1. 最简单也是最直接的方法:修改 /etc/systemd/system/multi-user.target.wants/docker.service 文件。
sudo vim /etc/systemd/system/multi-user.target.wants/docker.service # 找到ExecStart部分,在此行末尾添加--graph=你的目录,我的如下 [Service] Type=notify # the default is not to use systemd for cgroups because the delegate issues still # exists and systemd currently does not support the cgroup feature set required # for containers run by docker ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --graph=/home/hellxz/docker-home # 保存退出,接着让systemd重新读取这些service等的配置 sudo systemctl daemon-reload # 重启Docker服务 sudo systemctl restart docker
  1. 官方文档推荐的方法:修改 /etc/docker/daemon.json 文件。
{   "registry-mirrors": ["http://hub-mirror.c.163.com"],   "data-root": "/home/docker" }

保存退出后,重启Docker服务:

sudo systemctl restart docker

验证修改是否生效,可以通过再次查看 docker info 来确认Docker Root Dir 的位置:

[root@HNGC-SVR-QCCBigDataSvr-Dev2 docker]# docker info Client:  Debug Mode: false <p>Server: Containers: 0 Running: 0 Paused: 0 Stopped: 0 Images: 0 Server Version: 19.03.13 Storage Driver: overlay2 Backing Filesystem: xfs Supports d_type: true Native Overlay Diff: true Logging Driver: json-file Cgroup Driver: cgroupfs Plugins: Volume: local Network: bridge host ipvlan macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog Swarm: inactive Runtimes: runc Default Runtime: runc Init Binary: docker-init containerd version: 8fba4e9a7d01810a393d5d25a3621dc101981175 runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd init version: fec3683 Security Options: seccomp Profile: default Kernel Version: 3.10.0-693.el7.x86_64 Operating System: centos Linux 7 (Core) OSType: linux Architecture: x86_64 CPUs: 4 Total Memory: 31.26GiB Name: HNGC-SVR-QCCBigDataSvr-Dev2 ID: 6QOM:GCGS:F7NS:KOH4:SHLI:6RWQ:EHSA:YGMY:LG24:LS6S:MAVN:54HY Docker Root Dir: /home/docker Debug Mode: false Registry: <a href="https://www.php.cn/link/a2a5e1dc29759ed291e5ba5ecf1d6cbd">https://www.php.cn/link/a2a5e1dc29759ed291e5ba5ecf1d6cbd</a> Labels: Experimental: false Insecure Registries: 127.0.0.0/8 Registry Mirrors: <a href="https://www.php.cn/link/c209163f3e310b6c0a9a2c6489e22a8e">https://www.php.cn/link/c209163f3e310b6c0a9a2c6489e22a8e</a> Live Restore Enabled: false

通过上述步骤,我们已经成功地将Docker的数据目录位置更改为新的位置。

下一篇:产品经理的基本工作流程

© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享