Skip to content

Instantly share code, notes, and snippets.

@davisford
Last active August 29, 2015 14:18
Show Gist options
  • Save davisford/e63310e2176f15e6c4a3 to your computer and use it in GitHub Desktop.
Save davisford/e63310e2176f15e6c4a3 to your computer and use it in GitHub Desktop.
Trying to devise a solution so Docker bind-mount won't shadow dir/files inside container

I'd like to bind-mount my entire project into the container so updates on the host to the source are reflected in the container, but not have it shadow specific directories that were created there during the image build process. These files contain binary libraries that are architecture-specific (i.e. MacOS vs. Linux).

Here's a simple example of what I'm trying to accomplish - think of readme.txt as a binary:

On the host

$tree
.
├── Dockerfile
└── lib
    └── readme.txt

1 directory, 2 files
$cat lib/readme.txt 
this is from the host

On the container

See Dockerfile below

$docker run -t -i -v /path/to/test/:/test --rm foobar/test

root@a92565a735f7:/test# cat lib/readme.txt 
this is from the host

root@a92565a735f7:/test# cat /outside/readme.txt 
this is from the container

How to devise it so the volume doesn't shadow readme.txt? Obviously, I have a copy of the binary files I need outside the WORKDIR in /outside, and I could try to update the source to use that, but it is a bit of a pain, since all the software, including 3rd party components, etc. expect a standard directory structure.

Another possible solution is to only bind-mount all the specific files and directories I want and exclude others (e.g. /test/lib), but this gets to be a maintenance headache, too, since there are many files + directories, prone to human err.

One other solution I can think of is to make a data-only container and put all the binary libraries there, export it as a volume and mount that into the runtime container. This seems like the best option so far I guess, but I was hoping someone might have a clever trick that I haven't considered?

FROM debian:jessie
RUN mkdir /test
RUN mkdir /outside
WORKDIR /test
RUN ln -s /outside /test/lib
RUN touch /test/lib/readme.txt && echo "this is from the container" >> /test/lib/readme.txt
CMD ["/bin/bash"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment