-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add bind mount exclusion to prevent overwriting generated files with local files #6470
Comments
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: https://stackoverflow.com/questions/29181032/add-a-volume-to-docker-but-exclude-a-sub-folder 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. |
This would be a great feature to add, something we've lacked for almost a decade now. There was a workaround with symlinks and a second container but, sadly, as of 2020 that has also stopped working. |
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. |
Closing as there's nothing we can offer here from Docker Compose, until Docker engine offers such an "exclude" feature for bind mounts. |
Is there a way to do this yet? |
@nullbio there's no such thing as a "mount exclusion" in docker engine API (nor linux |
It's always annoying when I want to create a bind mount in order to synchronize
local
source code I'm editing, withcode from docker container
and all of the generated files.Whether it's
vendor
directory or abinary file
which eventually is used as anENTRYPOINT
orCMD
they are getting removed when the bind mount is done. And since thesefiles/directories
are not available onlocal machine
to avoid copying different binaries for different OS & ARCH inside linux container, docker removes them inside container as well when binding the source from local with the one from containerA 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:
As a workaround to avoid this situation with volumes instead of running the generated binary in
CMD or ENTRYPOINT
we run some sort ofshell script
which generates again the binary and then executes the binary and now theCMD/ENTRYPOINT
isreferencing
theshell script
.However would be a nice option with for initial bind mount some files which we choose would not be overwritten/removed in order to sync with local source code
docker-compose.yaml
init.sh
Dockerfile
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: