Centos 7 Docker data migration method

System environment:CentOS 7

Docker surroundings: 18.09.6

Date: 2020年10月25日, (PS: If you follow Dockerthe configuration file are subject to change again updated)

【Note】

  1. 在 /etc/docker/daemon.jsonAdd configuration "graph":"/data/docker"parameters: .

    graphIn Docker 17.05has been abandoned, the need to use data-rootinstead of (i.e. in the example herein)

  2. Most other programs are relatively old, it is the Dockerolder version of the program; there are other soft connection establishment or modification etc/xxx/dockermethod like in the previous Docker 版本or Ubuntushould be able to use, but if not, then the configuration file is also recommended to use this article This method 18、19has 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 dockerthe integrity of the original file 比如说权限信息( ) is recommended rsync, instead of directly mv.

yum -y install rsync

View the current dockerroot directory is located (must Dockerrun):

docker info
Insert picture description here

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/dockerof all the files in the directory, copied to the /new-path/dockerdirectory.

3. Modify the configuration file daemon.json

Modify docker 配置文件and point to the new data storage address

【Note】

  1. daemon.json There is no such file by default, just create it directly.
  2. vimThe command needs to be installed, if not, you can use the vicommand.
vim /etc/docker/daemon.json

Then add the following content ( jsonformat, 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 daemonfile is deleted, then dockercontinue to use /var/lib/dockeras the default path.

4. Restart

systemctl start docker 

5. Verify that the migration is successful

docker info

[Note] attention to check Docker Root Dirwhether the daemonpath configuration.

6. Clear the original docker root directory

[Note] recommended to empty /var/lib/dockerall the files in the path, rather than delete the entire directory.

cd /var/lib/docker

#清空当前目录下的所有文件(包含目录)
rm -rf ./*

Guess you like

Origin blog.csdn.net/peng2hui1314/article/details/109282823