修改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 分享