docker技巧

docker更改默认目录change docker root directory /var/lib/docker to another location

To relocate the Docker root directory, complete the following steps as root or a user with “sudo all” authority:

Create the necessary directory structure into which to move Docker root by running the following command. This directory structure must reside on a file system with at least 50 GB free disk space. Significantly more disk space might be required depending on your daily ingestion volumes and data retention policy. 建新目录
sudo mkdir -p /new_dir_structure

Move Docker root to the new directory structure: 移动数据
sudo mv /var/lib/docker /new_dir_structure

Edit the file /etc/docker/daemon.json. If the file does not exist, create the file by running the following command:
新建配置文件:
sudo vim /etc/docker/daemon.json

Add the following information to this file: 添加

{
“data-root”: “/new_dir_structure/docker”
}

After the /etc/docker/daemon.json file is saved and closed, restart the Docker services: 重启启动docker服务
sudo systemctl start docker

After you run the command, all Docker services through dependency management will restart.
Validate the new Docker root location:
验证:
docker info -f ‘{{ .DockerRootDir}}’