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

Vue realizes click flip effect

Use vue to simply implement a click flip effect f...

Web Design Experience: 5 Excellent Web Design Concepts Full Analysis (Pictures)

Unlike other types of design, web design has been ...

Stealing data using CSS in Firefox

0x00 Introduction A few months ago, I found a vul...

Vue.js implements the nine-grid image display module

I used Vue.js to make a nine-grid image display m...

Summary of the main attributes of the body tag

bgcolor="text color" background="ba...

How to install ELK in Docker and implement JSON format log analysis

What is ELK? ELK is a complete set of log collect...

Detailed summary of MySQL and connection-related timeouts

MySQL and connection related timeouts Preface: To...

Understand the principles and applications of JSONP in one article

Table of contents What is JSONP JSONP Principle J...

React and Redux array processing explanation

This article will introduce some commonly used ar...

Control the vertical center of the text in the HTML text box through CSS

When the height attribute of Text is defined, the ...

Our thoughts on the UI engineer career

I have been depressed for a long time, why? Some t...

Understanding MySQL clustered indexes and how clustered indexes grow

In this note, we briefly describe What is the B+T...

MySQL Series 3 Basics

Table of contents Tutorial Series 1. Introduction...

What command is better for fuzzy searching files in Linux?

1. Introduction This article mainly explains how ...