Docker Community Forums

Share and learn in the Docker community.

Converting from local host volume mount to docker volume without losing data

So I have a docker-compose file that has both postgresql and artifactory-pro as services. These services currently have volumes set up to the machine hosting the services. I was wondering if there was a way of moving the services from using locally hosted volume mounts to using docker-volume mounts without losing the the data within the local volume mounts?

Maybe I have these concepts confused. I’m still pretty green to Docker and was told that using local volume mounts isn’t very portable if this needs to be moved for any reason. Not sure if its as simple as creating a docker volume and cp the content from the local mount to the docker volume.

Is a docker volume even persistent? will the data be lost if the container is stopped? I get that 2 containers can share the same data but what happens to the data if the container goes down?

Actualy this is the cleanest solution: create an alpine container having the “-v” parameter of the old and new source, mounted to different folders inside the container. Then exec into the container and copy the files from source to target. This will work regardless of the volume plugin you used, wheter it uses a bind, remote-shore or block device type of storage.

1 . A docker volume is a handle to “real” storage. Of course data is persisted

2 . Data written in a container, not written into a container path with a volume mount, will be written into the containers - Of course data written into the container will be lost.

3 . I am not sure if i understand your “2 containres can share the same data” statement correct. A volume is a handle to real storage. It’s lifecycle is decoupled from the container. Bind and remote share type of volumes can be mounted to multiple volumes, though not all data is suitable to do so, e.g. using the same volume for two database containers will result in error, though using such a volume with services that exchange data using volumes, things should be finde.