How to Modify Docker’s Default Data Folder

Share it

Running low on disk capacity is a common challenge users encounter. When utilizing containerized Docker services, hitting that threshold means your deployments will cease to function. This occurs because your Linux system becomes incapable of performing additional write operations on the disk.

Thankfully, there is a practical remedy. This post will instruct you on altering Docker’s storage path for images, volumes, containers, etc., ensuring your projects can continue uninterrupted without the burden of disk space limitations.

To simplify, imagine this scenario: your disk is now 99% full, dangerously close to making your entire Linux system unusable. To address this issue, we’ve introduced a new 100GB disk to manage this situation and mounted it as the ” /data ” directory in our filesystem.

Our goal is to transfer all Docker resources to this new location, thus freeing up considerable space on the ” / ” root partition. This action will guarantee that Docker and our Linux system as a whole can operate seamlessly without any interruptions.

Step 1: Halt Docker Service

Before implementing any modifications, ensure all your containers are halted, and Docker is not in operation. This can be achieved with the following commands:

sudo systemctl stop docker.service
sudo systemctl stop docker.socketCode language: Bash (bash)

Keep in mind that this will result in all your Docker containers shutting down, causing inevitable downtime.

Step 2: Transfer Docker’s Data Directory

Docker stores all its data in a default directory, encompassing images, containers, volumes, and networks. Typically, on most Linux systems, this directory is ” /var/lib/docker/ “. While this arrangement suits initial setups, as the number of projects expands, so does the data volume.

Hence, the subsequent move involves relocating the existing Docker directory to a new site with more disk space. In our case, this involves the ” /data ” directory. Let’s initiate by creating a subdirectory, for instance, ” docker “, where we intend to transfer and store our Docker data going ahead.

sudo mkdir /data/dockerCode language: Bash (bash)

Now, it is time to act. Although you could apply the recursive cp command or even mv for data transfer, it is recommended to opt for the safest and most dependable approach, the rsync command. If not already present on your Linux distribution, you can effortlessly install the ” rsync ” package via your package manager.

To copy all data from ” /var/lib/docker/ ” to ” /data/docker/ ” directory, execute the following command, with the first argument serving as the source directory and the second as the destination.

sudo rsync -aP /var/lib/docker/ /data/docker/Code language: Bash (bash)
Move the Docker data directory to a new location.

🤞 Don’t miss these tips!

🤞 Don’t miss these tips!

Solverwp- WordPress Theme and Plugin