table of Contents
System environment:CentOS 7
Docker
surroundings: 18.09.6
Date: 2020年10月25日
, (PS: If you follow Docker
the configuration file are subject to change again updated)
【Note】
-
在 /etc/docker/daemon.json
Add configuration"graph":"/data/docker"
parameters: .graph
InDocker 17.05
has been abandoned, the need to usedata-root
instead of (i.e. in the example herein) -
Most other programs are relatively old, it is the
Docker
older version of the program; there are other soft connection establishment or modificationetc/xxx/docker
method like in the previousDocker 版本
orUbuntu
should be able to use, but if not, then the configuration file is also recommended to use this article This method18、19
has been tested in the new version ( ), so it is recommended to use this method.
Start the migration journey.
1. Environmental preparation
Installation rsync
, in order to ensure docker
the integrity of the original file 比如说权限信息
( ) is recommended rsync
, instead of directly mv
.
yum -y install rsync
View the current docker
root directory is located (must Docker
run):
docker info
2. Migrate data
# 先关闭 Docker 服务:
systemctl stop docker
# 然后复制文件到新目录
rsync -avz /var/lib/docker/ /new-path/docker/
/new-path/docker/
Is the new root directory path, the operation /var/lib/docker
of all the files in the directory, copied to the /new-path/docker
directory.
3. Modify the configuration file daemon.json
Modify docker 配置文件
and point to the new data storage address
【Note】
daemon.json
There is no such file by default, just create it directly.vim
The command needs to be installed, if not, you can use thevi
command.
vim /etc/docker/daemon.json
Then add the following content ( json
format, if there are other configurations, remember to add a comma, then add it data-root
, otherwise an error will be reported)
{
"data-root":"/new-path/docker"
}
wq
Just save, if not, it will be created automatically.
[Note] If this daemon
file is deleted, then docker
continue to use /var/lib/docker
as the default path.
4. Restart
systemctl start docker
5. Verify that the migration is successful
docker info
[Note] attention to check Docker Root Dir
whether the daemon
path configuration.
6. Clear the original docker root directory
[Note] recommended to empty /var/lib/docker
all the files in the path, rather than delete the entire directory.
cd /var/lib/docker
#清空当前目录下的所有文件(包含目录)
rm -rf ./*