Docker Community Forums

Share and learn in the Docker community.

Docker volume deleting content from container when started


I want to create a docker volume for a specific folder in the container and maps this folder locally.
This is my command

docker run -d --link httpd:httpd --name=test10 -v /data/docker/volumes/test10:/jboss-eap-7.0/domain/configuration bcf43571d397 tailf /dev/null

The result is an empty folder in container test10 /jboss-eap-7.0/domain/configuration
an empty folder in /data/docker/volumes/test10

What am I doing wrong?
When I create files in the container and outside they appear in both sides.

What volume mapping does is simply create a link between the local folder and the one in the docker host.

I think you have to copy the contents of /jboss-eap-7.0/domain/configuration into you local folder the first time.

It should not be like this, in my previous job, I used to create the volumes and all was fine. Here this doesn’t work. I can’t remember the docker version in my previous job but here it is Docker version 1.12.0
Could this be effecting?

Everything you describe sounds correct:

  • You have an empty directory on the host.
  • When you use docker run -v to bind-mount it into a container, you see the same content there.
  • If you create or edit a file either on the host or in the container in the shared directory, the same change appears on the other side.

What are you expecting to work differently?

(What are you trying to do with this container setup in the first place? It very vaguely looks like you’re trying to mount a host directory into a container that does nothing. On current Docker you should look at the docker volume command set to manage containers, rather than the older data-volume container pattern.)


What I wanted is to build a container and take the content in the folder /jboss-eap-7.0/domain/configuration and map it on the docker host. So initially on the Docker host, I have an empty folder. I wanted this folder to be populated by the content created in the container. This was not working.

Actually after some testing I found a work around. I created a named volume and this copied the new content from the container to my empty host folder. The only issue is that I have to create a symbolic link to the default path. Not sure if this can be changed. Below are the commands

docker run -d -v benjamin:/jboss-eap-7.0/domain/configuration/ --name=test10 bcf43571d397

docker inspect test10 | grep -A1 volume
"Source": “/var/lib/docker/volumes/benjamin/_data”,
“Destination”: “/jboss-eap-7.0/domain/configuration”,

cd /data/docker/volumes/test10/ #this is the path on my docker host
ln -s /var/lib/docker/volumes/benjamin/_data/ benjamin

cd benjamin
ls host-master.xml host_xml_history domain.xml host-slave.xml
benjamin domain_xml_history host.xml