Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move docker bind-mount to volume

Tags:

docker

volumes

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 ?

like image 723
fmdaboville Avatar asked Apr 17 '18 21:04

fmdaboville


People also ask

What is bind mount a volume in Docker?

Bind mounts have been around since the early days of Docker. Bind mounts have limited functionality compared to volumes. When you use a bind mount, a file or directory on the host machine is mounted into a container. The file or directory is referenced by its absolute path on the host machine.

What is the difference between Docker volume and bind mount?

Though both methods are similar, there is a slight difference. Docker manages Volumes and is usually not affected by other processes running on the same host. In contrast, Bind Mounts are just directories on the host file system and may be modified by other processes other than docker.

What is the purpose of a bind mount for a Docker container?

Bind mounts will mount a file or directory on to your container from your host machine, which you can then reference via its absolute path. To use bind mounts, the file or directory does not need to exist on your Docker host already. If it doesn't exist, it will be created on demand.


1 Answers

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.

like image 73
fly2matrix Avatar answered Nov 15 '22 05:11

fly2matrix