How to move Docker to attached volume in DigitalOcean?

In this article, I would explain how you can move your current installation of Docker to the attached volume of your DigitalOcean droplet.

It may happen that you have a droplet with good specifications running but you are running out of storage. If you try to upgrade the droplet itself for the storage, you will end up with more CPU and RAM which is only going to increase the cost even higher. It is always better to just go for additional volume to your existing droplet. The additional volume works just like another partition or drive for your droplet.

First we have to stop Docker service

sudo systemctl stop docker
sudo systemctl stop docker.socket
sudo systemctl stop containerd

Next we need to know which one is your new mounted volume storage

df -h

We will see a result similar to this


The highlighted record in yellow is the our mounted volume. The volume name may vary in your droplet. We will change directory the volume and make a directory for our docker:

cd /mnt/volume_blr1_01
mkdir lib

Now we have to find the location of our existing installation of Docker. Usually it will be in /var/lib/docker. We will now move our entire folder of Docker to the new location (it would take a while for moving, depending on the size of the directory).

mv /var/lib/docker /mnt/volume_blr1_01/lib

Once the folder has been successfully moved, you have to edit (or create) daemon file for docker to point to the newly located storage by running the following command

sudo nano /etc/docker/daemon.json

And paste the following then save and exit

  \"data-root\": \"/mnt/volume_blr1_01/lib/docker\"

Now start docker

sudo systemctl start docker

You can verify the newly updated path by running the following command

docker info -f \'{{ .DockerRootDir}}\'

Now you have your Docker running from the mounted storage.






Leave a Reply

Your email address will not be published. Required fields are marked *