Docker Community Forums

Share and learn in the Docker community.

Docker not mouting directory when running detached

Hi.
I am trying to have a /var/www/html directory shared with the hosts pwd.

The following command works just as expected:

docker run -it -v “$(pwd)”:/var/www/html --name imgName -p 8081:80 imgName /bin/bash

But when I try to run the container without -it like:

docker run -d -v “$(pwd)”:/var/www/html --name imgName -p 8081:80 imgName

Then the files which I added even before running the container, are not in there.

Do you have any ideas, what could cause this and how I could fix it?
I want, that when I edit/add/remove a file in pwd, that these changes are also made in the container.

The following experiments where made, without success:

docker run -v “$(pwd)”:/test --name imgName -d -p 8081:80 imgName

docker run -v “$(pwd)”:/var/www/html --name imgName -p 8081:80 imgName

docker run -v “$(pwd)”:/test --name imgName -d -p 8081:80 imgName

docker run -d -v “$(pwd)”:/var/www/html --name imgName -p 8081:80 imgName

docker run -d --mount type=bind,source=$(pwd),target=/var/www/html --name imgName -p 8081:80 imgName

docker run -d --mount type=bind,source=$(pwd),target=/test --name imgName -p 8081:80 imgName

docker run -d -P --name imgName -v “$(pwd)”:/var/www/html:z -p 8081:80 imgName

docker run -d --name imgName -v “$(pwd)”:/var/www/html:Z -p 8081:80 imgName

docker run -d -P --name imgName -v “$(pwd)”:/test -p 8081:80 imgName

docker run -d -it --name imgName -v “$(pwd)”:/var/www/html imgName

docker run -it -v “$(pwd)”:/var/www/html/aaaa --name imgName -d -p 8081:80 imgName /bin/bash

docker run -d -it -v “$(pwd)”:/var/www/html --name imgName -p 8081:80 imgName

Additional Informations:

Docker version 18.06.3-ce, build d7080c1
Docker image derived from: php:7.2-apache

Thanks in advance.