How to Safely Move Docker Volumes to a Larger Partition

by Tyrese Harris
14 minutes read

How to Safely Move Docker Volumes to a Larger Partition


Responses Docker Volume Larger Separating Featured

By default, Docker store fronts every little thing within “/var/lib/docker”, which is situated on the root (/) separating. As your cans flourish, this folder can refill proper away. If you notice that your server is running sluggish, fail to save file, or collision randomly, it is probably offered that the root separating possesses sprinted out of elbowroom. In this overview, we’ll tread you via the strategies to move your Docker volume (or file) to an additional separating and unshackle upward elbowroom in the root separating.

Why Do You Need to Responses Docker Volumes to An additional Separating

Docker cans oftentimes collect big amounts of congruent file. Over time, this file can swipe in the storage elbowroom of your root separating. Transmitting Docker allotments to an additional separating helps you to:

  • unshackle elbowroom on the root filesystem
  • obstruct mechanism collisions due to disk fatigue
  • emporia big masterstroke file on perpetrated storage
  • improve on the whole storage management

For example, database cans such as MySQL or PostgreSQL might emporia gigabytes of file within allotments. Transmitting those allotments to a bigger perpetrated separating can aid to hold ago mechanism stability.

Locate the Docker Volume Directory

Before sending a Docker volume, we first have to situate whereby Docker store fronts it on the mechanism. Dashed the consequent command to list with one voice obtainable Docker allotments:

docker volume ls
Weigh Docker Volumes
How to Safely Move Docker Volumes to a Larger Partition 26

After uncovering the volume tag, sprinted the command under to evaluate that particular volume:

docker volume inspect volume_name

This command display displays defined lays out about the volume. In the output, substantial appearances for the Mountpoint sector. It confirms the specific brochure whereby Docker store fronts the volume file.

Weigh Particular Docker Volume
How to Safely Move Docker Volumes to a Larger Partition 27

Responses the Totality Docker Information Root

One means to move Docker file to a opposite separating is by relocating the entire Docker storage brochure, which entails allotments, images, cans, and logs. It’s the cleanest and safest approach if “/var/lib/docker” is loading upward.

For this nondiscriminatory, first, you have to safeguard against the Docker solution to make sure certainly no documents alteration throughout the mobility:

sudo systemctl stop docker

Next, you can copy the Docker file wearing the rsync command:

sudo rsync -avxP /var/lib/docker/ /path/to/new/partition/docker-data/

Note: Equalize the “/course/to/neoteric/separating/” to the course of the neoteric separating whereby you twinge to move the folder to.

This command duplicates the Docker brochure while maintaining sanctions and substantiating progress throughout the transfer.

Xerox Docker Information Rsync
How to Safely Move Docker Volumes to a Larger Partition 28

Alternatively, you can gain utility of the consequent command, which preserves second Docker weakness such as hard affiliations, ACLs, and prolonged weakness:

sudo rsync -aHAX --info=progress2 /var/lib/docker/ /mnt/docker-data/

This difference is recommended as shortly as migrating Docker file offered that it preserves more filesystem metadata and lends a clearer on the whole progress signs and indications and symptom.

After this, rename the ratty file brochure to ago it upward in the past separating it.

sudo mv /var/lib/docker /var/lib/docker.old

Now, improve Docker’s arrangement by opening the daemon record with this command:

sudo nano /etc/docker/daemon.json

Add the consequent content to this record:

{
"data-root": "/path/to/new/partition/docker-data"
}
Update Docker Arrangement
How to Safely Move Docker Volumes to a Larger Partition 29

Last however not the horribly least, restart Docker with sudo systemctl start docker. After this, you can attest the neoteric Docker file brochure with the consequent command:

docker info | grep "Docker Root Dir"
Attest Docker Desired Information Directory
How to Safely Move Docker Volumes to a Larger Partition 30

If every little thing is alright, fetch rid of the ratty ago-up:

sudo rm -rf /var/lib/docker.old

Responses With one voice Docker Information Making gain utility of of Docker Desktop computer (GUI Approach)

Docker Desktop computer permits you to move with one voice Docker file to an additional separating by equalizing the Disk Image Locale. This substitute transmits every little thing stored by Docker, involving images, cans, allotments, and the build cache, to a neoteric locale on your mechanism.

To execute this, responsive Docker Desktop computer and peruse to Installments, get involved in ResourcesProceeded, and then situate the Disk Image Locale substitute. 

Disk Image Locale
How to Safely Move Docker Volumes to a Larger Partition 31

Click Peruse and advice a folder on the neoteric separating or drive whereby you twinge Docker to emporia its file, such as “/mnt/newdisk/docker-file”. After picking the neoteric locale, click Use & Restart. Docker Desktop computer will not surprisingly then restart and move with one voice current Docker file to the picked separating.

Equalize Separating
How to Safely Move Docker Volumes to a Larger Partition 32

Note: This assignments with one voice Docker file. There is presently certainly no GUI substitute to move user allotments.

Relocate Lone Particular Volume Information

You can move a particular Docker volume to an additional separating and gain utility of it with your canister via a host bind void. This approach is humble, safeguard, and uncomplicated to ago upward. Before sending the volume, safeguard against the canister that utilises it:

docker stop container_name

After this, gain utility of rsync to move with one voice file strongly to your neoteric brochure:

sudo rsync -a /var/lib/docker/volumes/my_volume/_data/ /data/docker/my_volume/

This will not surprisingly copy every little thing from the ratty volume to “/file/docker/my_volume”.

Edit your “docker-build.yml” record to gain utility of a bind void instead of a Docker-foreclosed care of volume:

services:
  my_service:
    volumes:
      - /data/docker/my_volume:/container/path

Equalize /container/path with the course within the canister whereby the volume was originally mounted. Then redeploy the canister with the consequent command:

docker-compose up -d

Coating Upwards

Transmitting Docker allotments or the entire Docker file brochure to a bigger separating releases upward elbowroom on your root filesystem and preserves your server stable. Cylinders perpetuate running smoothly without any confusion of file loss, and future storage management becomes much less convoluted.

If relocating the entire Docker brochure isn’t decent, you can still redeem elbowroom wearing assorted other strategies. These require pruning unused cans, images, networks, and caches with docker mechanism trim or user trim commands, and wearing Linux bind mounts to move big catalogs without influencing Docker’s runtime.

Related Posts