runsisi's

technical notes

设置 docker 数据目录

2020-05-18 runsisi#docker

docker 的默认数据目录为 /var/lib/docker:

$ docker info
...
 Docker Root Dir: /var/lib/docker

# tree -L 1 /var/lib/docker
/var/lib/docker
├── builder
├── buildkit
├── containers
├── devicemapper
├── image
├── network
├── plugins
├── runtimes
├── swarm
├── tmp
├── trust
└── volumes

有时为了缓解系统盘空间不够的情况,可能需要将这个目录设置到别的路径,此时可以通过修改配置文件或者设置命令行选项的方式来实现。

修改配置文件:

# vi /etc/docker/daemon.json
{
  "data-root": "/data/runsisi/docker-data/"
}

或者直接修改命令行参数:

# mkdir -p mkdir -p /data/runsisi/docker-data/
# dockerd -D --data-root /data/runsisi/docker-data/

查看修改后的数据目录:

# docker info
...
 Docker Root Dir: /data/runsisi/docker-data/

参考资料

How to change the docker image installation directory?

https://stackoverflow.com/questions/24309526/how-to-change-the-docker-image-installation-directory

CHANGE DOCKER DATA DIRECTORY ON DEBIAN

https://blog.adriel.co.nz/2018/01/25/change-docker-data-directory-in-debian-jessie/

-g and --graph flags on dockerd

https://docs.docker.com/engine/deprecated/#-g-and---graph-flags-on-dockerd