Docker Community Forums

Share and learn in the Docker community.

Bind host path to container content not working

Hi all

I’m trying to use this image : https://hub.docker.com/r/vimagick/mantisbt/dockerfile

Container is working fine, but to not loosing customisation if container stop, I wanted to bind an local path from my host to the container (the web server content).
So I tried to execute this command :

docker run -d -it --mount type=bind,src=/mnt/Test3/,dst=/var/www --name Mantis -p 4481:80 vimagick/mantisbt:latest

Container start well but no files are available in my host folder /mnt/Test3
subfolder "html’ from /var/www/ is created in the /mnt/Test3 folder but after no files etc…

Any idea to help me ? :slight_smile:

The volume declaration in the Dockerfile sets a bit of metadata on the image that tells docker run to define an anonymous volume at that location any time a container is made from that image. This is not a named volume or host mount, but it has a lot in common with both (they are all bind mounts by default, and anonymous volumes are listed in docker volume ls along with named volumes).

However, when you specify a host mount to the same container directory, that takes precedence (two volume mounts to the same directory inside the container will not happen). Any modifications to that directory by the commands running inside the container will be visible on the host, but the directory itself will not be initialized by the image contents.

If you want to initialize a host directory with image contents, you can use a named volume that performs a bind mount. There are a few differences in behaviour from the host mount. Mainly the directory must exist in advance, and inside a compose file you must use absolute paths instead of relative ones.