Hi I'm having trouble syncing local project files with a Docker container. I'm using a Dockerfile that has VOLUME directive:
VOLUME [ "/usr/local/src/project-dir/public/bundles"
When I'm running the container with docker compose with following service using bind mount:
app:
volumes:
- type: bind
source: .
target: /usr/local/src/project-dir
Now when inside the container I use a command that generates some static assets to /usr/local/src/project-dir/public/bundles
, those files don't sync back to the local filesystem. Can You tell me why?
I expect the files generated in the container in /usr/local/src/project-dir/public/bundles
, to sync with local filesystem. However they do generate in the container but are nowhere to be seen in the host system.
Your issue is the VOLUME statement in the Dockerfile.
Your bind works correctly in that it maps your current host directory to /usr/local/src/project-dir
.
But the VOLUME statement causes docker to create a docker volume and map that to /usr/local/src/project-dir/public/bundles
. Any files you create in /usr/local/src/project-dir/public/bundles
and below will be in the docker volume and not reflected in the bound directory.
To fix it, you can remove the VOLUME statement in the Dockerfile. Then all files you create in /usr/local/src/project-dir
or below will be in the mapped directory on the host.