I have the following problem. I am trying to mount a volume using docker-compose. When no volume is mounted, the container works perfectly fine. However, as soon as I attempt to mount a local directory to a path in the Docker container, the target path becomes empty, and the Docker container becomes corrupted. It appears as though the local folder is overwriting the folder in the container. This issue is not specific to a particular image; it affects other Docker containers as well. In Docker Desktop, the corresponding paths are listed under File Sharing. Here is an example file:
version: '3'
services:
shop:
container_name: Dev_shopware6
image: dockware/dev:6.5.3.3
ports:
- "22:22" # ssh
- "80:80" # apache2
- "443:443" # apache2 https
- "8888:8888" # watch admin
- "9998:9998" # watch storefront proxy
- "9999:9999" # watch storefront
- "3306:3306" # mysql port
volumes:
- ./src:/var/www/html
networks:
- web
environment:
- XDEBUG_ENABLED=0
Dev_shopware6 | AH00112: Warning: DocumentRoot [/var/www/html/public] does not exist
Dev_shopware6 | AH00112: Warning: DocumentRoot [/var/www/html/public] does not exist
Im working on MacOS with Docker Desktop
Projectstructure
.
├── docker
│ └── db
├── docker-compose.yml
├── readme.md
└── src
4 directories, 2 files
ls -la inside the container
www-data@63f6c46e9787:~/html$ ls -la
total 492
drwxr-xr-x 1 www-data www-data 4096 Jul 18 15:49 .
drwxrwxrwx 1 root root 4096 Jul 18 15:49 ..
-rw-r--r-- 1 www-data www-data 1247 Jul 18 15:42 .env
-rw-r--r-- 1 www-data www-data 647 Jul 18 15:42 .gitignore
-rw-r--r-- 1 www-data www-data 369 Jul 18 15:42 .htaccess
-rw-r--r-- 1 www-data www-data 350 May 3 10:38 README.md
drwxr-xr-x 1 www-data www-data 4096 Jul 18 15:42 bin
-rw-r--r-- 1 www-data www-data 1769 Jul 18 15:44 composer.json
-rw-r--r-- 1 www-data www-data 415799 Jul 18 15:44 composer.lock
drwxr-xr-x 1 www-data www-data 4096 Jul 18 15:42 config
drwxr-xr-x 1 www-data www-data 4096 Jul 18 15:42 custom
-rw-r--r-- 1 www-data www-data 334 Jul 18 15:42 docker-compose.override.yml
-rw-r--r-- 1 www-data www-data 1070 Jul 18 15:42 docker-compose.yml
drwxr-xr-x 1 www-data www-data 4096 Jul 18 15:43 files
-rw-rw-rw- 1 www-data www-data 0 Jul 18 15:43 install.lock
drwxr-xr-x 1 www-data www-data 4096 Jul 18 15:43 public
-rw-r--r-- 1 www-data www-data 6427 Jul 18 15:42 symfony.lock
drwxr-xr-x 1 www-data www-data 4096 Jul 18 15:44 var
drwxr-xr-x 1 www-data www-data 4096 Jul 18 15:44 vendor
2
Answers
From the docs:
So basically, you can’t bind mount a host directory on top of an existing directory in the image without ‘hiding’ the directory content in the image.
You mount your
./src
directory on/var/www/html/
and that hides everything in/var/www/html/
and below.Based on your replay in comments I assume you want to create a development environment for the project you have shared in the comment section.
You can do the following:
Run you container without the mount line
Run this command
docker cp <container name>:/var/www/html/ ./src
(the path may vary based on your system)Run you container with the mount line
This way you your src folder will have all the files from the original container. The project you shared have public folder so everything should work well.