docker set rootdir: set the default data storage location of /var/lib/docker (data-root or graph)

insert image description here

Docker uses the union file system (UnionFS) to create a container image, which contains a read-write layer (write layer) and a read-only layer (read-only layer).

By default, Docker's write layer is stored under /var/lib/dockerthe directory, including the container's file system, logs, and metadata. However, if you have limited directory space on your host machine /var/lib/docker, you may need to store the Docker write layer (and other data) elsewhere, such as an external hard drive or network storage.

To store Docker's write layer in another location, you can specify a new root directory (root directory) by modifying Docker's configuration file. Here are the steps to do that:

  1. Stop the Docker service:
sudo systemctl stop docker
  1. Backup the original Docker configuration file:
sudo cp /etc/docker/daemon.json /etc/docker/daemon.json.bak
  1. Edit the Docker configuration file /etc/docker/daemon.json, specifying data-rootthe property as the new Docker root directory. For example, to change Docker's root directory to /mnt/docker-root, the following configuration could be used:
{
    
    
  "data-root": "/mnt/docker-root"
}
  1. Save and close the file.

  2. Start the Docker service:

sudo systemctl start docker

Docker's write layers will now be stored in the new root directory /mnt/docker-rootinstead of the default /var/lib/dockerdirectory.

Note that before specifying a new Docker root directory, you need to ensure that the directory already exists and has sufficient permissions for the Docker process to write to the directory. Otherwise, Docker will fail to start or create containers.

--data-rootIn addition to specifying the Docker root directory through configuration files, you can also use parameters to specify the root directory when running Docker commands . For example:

sudo dockerd --data-root /mnt/docker-root

This will start the Docker daemon and set Docker's root directory to /mnt/docker-root.

Guess you like

Origin blog.csdn.net/a772304419/article/details/131571288