應用環境:
docker安裝時如果不指定家目錄(也就是工作目錄),一般默認工作目錄是 /var/lib/docker ,很多時候需要修改到大容量磁盤上進行存儲,這里記錄一下修改默認路徑為 /data/docker 。
網上搜羅一番,兩種方法:
①添加並配置 /etc/docker/daemon.json 文件
②修改systemd管理的docker服務文件 /usr/lib/systemd/system/docker.service
測試環境:
容器運行時 | 版本 | 安裝方式 |
docker-ce | 18.09.5 | yum |
操作步驟:
前提:查看當前docker運行的工作目錄
[root@server-1 ~]# docker info |grep "Docker Root Dir"
方法①
1.新建或者編輯 /etc/docker/daemon.json
{ "data-root": "/data/docker" }
2.重啟docker
systemctl restart docker
方法②
1.編輯文件 /usr/lib/systemd/system/docker.service
[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 --data-root=/data/docker ExecReload=/bin/kill -s HUP $MAINPID TimeoutSec=0 RestartSec=2……
2. 重啟docker
systemctl daemon-reload
systemctl restart docker
注意:目前網上大多數配置參數是 --graph ,其實這是老版本中的使用方法,新版本已經拋棄,改用了 --data-root ,具體可以通過命令 dockerd --help 查看使用的參數。
參考:
https://github.com/moby/moby/pull/28696
結束.