'Move docker bind-mount to volume
Actually, I run my containers like this, for example :
docker run -v /nexus-data:/nexus-data sonatype/nexus3
^
After reading the documentation, I discover volumes that are completely managed by docker. For some reasons, I want to change the way to run my containers, to do something like this :
docker run -v nexus-data:/nexus-data sonatype/nexus3
^
I want to transfer my existing bind-mount to volumes.
But I don't want to lose the data into /nexus-data
folder, is there a possibility to transfer this folder, to the new volume, whitout restart everything ? Because I've also Jenkins and Sonar containers for example, I just want to change the way to have persistent data. The is a proper way to do this ?
Solution 1:[1]
You can try out following steps so that you will not loose your current nexus-data.
#>docker run -v nexus-data:/nexus-data sonatype/nexus3
#>docker copy /nexus-data/. <container-name-or-id>:/nexus-data/
#>docker stop <container-name-or-id>
#>docker start <container-name-or-id>
docker copy will copy data from your host-machine's /nexus-data folder to container's FS /nexus-data folder which is your mounted volume.
Let me know if you face any issue while performing following steps.
Solution 2:[2]
Here's another way to do this, that I just used successfully with a Heimdall container. It's outlined in the documentation for the sonatype/nexus3 image:
- Stop the running container (e.g. named
nexus3
) - Create a docker volume called
nexus-data
, creating it with the following command:docker volume create nexus-data
) - By default, Docker will store the volume's content at
/var/lib/docker/volumes/nexus-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/nexus-data/* /var/lib/docker/volumes/nexus-data/_data/
- Restart the
nexus3
container with$ docker run -v nexus-data:/nexus-data sonatype/nexus3 --name=nexus3
- Your container will be back up and running, with the files persisted in the directory
/path/to/nexus-data/
now mirrored in the docker volume. Check if functionality is the same, of course, and if so, you can delete the/path/to/nexus-data/
directory
Q.E.D.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | call-in-co |