Docker - move data from Bind Mount to Volume

I recently decided to move the persistent data for this Ghost blog from a Bind Mount to a dedicated Docker Volume, this was mainly due to issues with backing up a running SQL database. Below is the simple process I followed.

  • Stop the running container (For example Dozzle).
  • Create a docker volume called dozzle-data, creating it with the following command:
docker volume create dozzle-data
  • By default, Docker will store the volume's content at
/var/lib/docker/volumes/dozzle-data/_data/
  • Simply copy the directory where you previously had been using a bind mount to the aforementioned volume directory (you'll need super user privileges to do this, or for the user to be part of the docker group).
 cp -R /path/to/dozzle-data/* /var/lib/docker/volumes/dozzle-data/_data/
  • Restart the dozzle container
  • Your container will be back up and running, with the files persisted in the directory /path/to/dozzle-data/ now mirrored in the docker volume.

Check if functionality is the same, of course, and if so, you can delete the Bind Mount directory.