Add bind mount exclusion to prevent overwriting generated files with local files #6470
It's always annoying when I want to create a bind mount in order to synchronize
A solution to this might be to to do the bind mount first then use the snapshot fs which was created when the image was build, which will first bind mount the sources then allow the scripts which generate the binaries/directories to execute without being removed
Another solution would be to indicate in the volumes section some sort of exclude list when binding mount for the first time, somethings that would look like this:
volumes: - .:/usr/app: exclude: - fileA - fileB - dirA/
As a workaround to avoid this situation with volumes instead of running the generated binary in
version: "3.7" services: redis: image: redis restart: always volumes: - redis-data:/data networks: - visits command: redis-server --appendonly yes visits-app: build: . restart: always ports: - "8080:8080" volumes: - ./:/usr/app networks: - visits # if this custom command is missing then we get an error that there is no node_modules # but in Dockerfile we indeed genereated node_modules by running npm install command: sh /usr/app/init.sh networks: visits: volumes: redis-data:
npm install npm start
FROM node:alpine ENV PORT 8080 EXPOSE $PORT WORKDIR /usr/app COPY ./package.json ./ RUN npm install COPY . . CMD npm start
Thank you for the awesome project and let me know if such a feature is a valid one and does not come against docker philosophy or if you need any help in implementing it
The text was updated successfully, but these errors were encountered:
Thanks for the suggestion @steevehook !
One thing you can do is restructuring your source tree so that you can mount (in docker-compose.yml:18) just important part which is, lets say a
I think implementing volume exclusions could lead to awkward corner cases.
If the mounting is for a performance issue then, looking at your
The biggest problem that this would alleviate is for
There are countless stackoverflow threads and blog posts about this, here's a few:
The basic gist is that when doing local development you want to have the files except for node modules shared between host and container. The docker image already installs the dependencies for the linux version, which is then overwritten with either an empty node_modules or in some cases node_modules for a different OS like windows or mac:
The common workaround is a named volume:
The big downside is then you have some extra volume to deal with and remember to remove when updating dependencies.
I'd second this. We are currently mounting our local work directory into the docker container so we can do some validations before pushing them up to Jenkins. Unfortunately, there is 1 file that has to be different locally vs in the container (local.properties) and as such we have had to resort to using the entrypoint to symlink every file/directory once mounted then remove that entry. That was working fine until AGP (Android Gradle) 7 which no longer works correctly with symlinks. As such, I'm once again looking for a workaround to the missing exclude file option.
bind mount is managed by docker engine, not compose. And those are actually Linux features to define a mount for container-visible filesystem to access some parts of host's filesystem. We only expose the available lower-level features. Linux mounts does not offer anything like "exclusions" we could rely on.