How to migrate the data directory in Docker

How to migrate the data directory in Docker

View Disk Usage

# du -hs /var/lib/docker/ 
237G /var/lib/docker/

# docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 7 2 122.2GB 79.07GB (64%)
Containers 2 2 61.96GB 0B (0%)
Local Volumes 0 0 0B 0B
Build Cache 0 0 0B 0B

Disk Cleanup (Do Not Use It Lightly)

# The docker system prune command can be used to clean up disks, delete closed containers, unused data volumes and networks, and untagged images.
# The docker system prune -a command can delete all Docker images that are not used by containers. Note that these two commands will delete the temporarily closed containers and the Docker images that are not currently in use.

Migrate data

【Stop Docker】
# systemctl stop docker

Create a new docker directory
# mkdir -p /home/docker/lib

Migrate the /var/lib/docker directory
(Note: You can directly mv, make sure the disk is large enough)
# rsync -avz /var/lib/docker /home/docker/lib/  

【Add configuration】
Check whether /etc/systemd/system/docker.service.d/devicemapper.conf exists. If it does not exist, create it.
# mkdir -p /etc/systemd/system/docker.service.d/
# vi /etc/systemd/system/docker.service.d/devicemapper.conf
 (Note: devicemapper.conf adds configuration: when syncing, the parent folder should be synchronized together. The actual directory should be in /home/docker/lib/docker )
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd --graph=/home/docker/lib/docker

[Reload Docker] 
# systemctl daemon-reload
# systemctl restart docker
# systemctl enable docker

Check docker info
# docker info | grep "Docker Root Dir"
Is it changed to: /home/docker/lib/docker

Check the image
# docker images

【Cleaning up original data】
After confirming that the container is OK, delete the files in the /var/lib/docker/ directory.
# rm -rf /var/lib/docker

This is the end of this article about the methods and steps of docker migration data directory. For more relevant content about docker migration data directory, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • 5 ways to migrate Docker containers to other servers
  • Docker time zone issue and data migration issue
  • Docker image import, export, backup and migration operations
  • Detailed explanation of migrating local Docker containers to the server
  • Migrating the blog to Docker
  • How to migrate docker containers across servers

<<:  Why is the disk space still occupied after deleting table data in MySQL?

>>:  Detailed explanation of the difference between the default value of the CSS attribute width: auto and width: 100%

Recommend

CSS Transition expands and collapses elements by changing the Height

A common development need is that we want to coll...

Detailed explanation of root directory settings in nginx.conf

There are always some problems when configuring n...

6 interesting tips for setting CSS background images

Background-image is probably one of those CSS pro...

JavaScript implements large file upload processing

Many times when we process file uploads, such as ...

Solution for applying CSS3 transforms to background images

CSS transformations, while cool, have not yet bee...

Vue implements form validation function

This article mainly describes how to implement fo...

MySQL cleverly uses sum, case and when to optimize statistical queries

I was recently working on a project at the compan...

Detailed View of Hidden Columns in MySQL

Table of contents 1. Primary key exists 2. No pri...

Embedded transplant docker error problem (summary)

After a long period of transplantation and inform...

Example code for Html layered box-shadow effect

First, let’s take a look at the picture: Today we...

Web Design Experience: Self-righteous Web Designers

1. Trash or Classic? Web technology updates very ...

How to enable the root account in Ubuntu 20.04

After Ubuntu 20.04 is installed, there is no root...