current position:Home>Modify the default storage path of docker under Linux

Modify the default storage path of docker under Linux

2022-01-26 22:23:15 Yan Long

Docker Installed by default , Will use /var/lib/docker/ Directory as storage directory , It is used to store the pulled images and created containers . This path is the system storage directory , Generally, the space is relatively small . If you create a large container, the system space will soon run out . Here's a record of docker The default path of is changed to data disk .

Operation plan

  1. View disk information , Choose one with large disk space as docker The default installation location for
$ df -lh
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        99G  4.1G   91G   5% /
devtmpfs        7.7G     0  7.7G   0% /dev
tmpfs           7.8G     0  7.8G   0% /dev/shm
tmpfs           7.8G  266M  7.5G   4% /run
tmpfs           7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/vdb1       197G  399M  187G   1% /data
tmpfs           1.6G     0  1.6G   0% /run/user/0
  1. see docker Current storage path
$ docker info
...
OSType: linux
Architecture: x86_64
CPUs: 8
Total Memory: 15.42GiB
Name: VM-125-197-centos
ID: OLLW:ZRBS:Z2XV:34ER:NKGJ:NNH4:LKOX:YX3U:BSDO:SL2I:F7S7:CMSM
Docker Root Dir: /data/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
...
  1. Modify the configuration file /etc/docker/daemon.json
{
    ...
    "data-root": "/data/docker/",
    ...
    
}
  1. Restart the service
systemctl restart docker
  1. Check to confirm docker Current storage path
OSType: linux
Architecture: x86_64
CPUs: 8
Total Memory: 15.42GiB
Name: VM_14_9_centos
ID: OLLW:ZRBS:Z2XV:34ER:NKGJ:NNH4:LKOX:YX3U:BSDO:SL2I:F7S7:CMSM
Docker Root Dir: /data/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/

END!

copyright notice
author[Yan Long],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201262223131809.html

Random recommended