6

If I have a directory d1/, I know I can mount it at /mountPoint inside a Docker container by doing this:

docker run -v /path/to/d1:/mountPoint ...

However, I have two directories d1/ and d2/ (let's say they contain files a.txt and b.txt respectively).

I want to mount the union of these two directories at /mountPoint in my container, i.e. I want /mountPoint/a.txt and /mountPoint/b.txt to exist.

Given that Docker uses UnionFS a lot internally, I am rather hoping there are options to do a union mount at a specific path inside a container, but I can't find them if so.

David North
  • 1,247
  • 1
  • 14
  • 32
  • you can mount multiple volumes as far as I know. ``` docker run -v /path/to/d1:/mountPoint -v /path/to/d2:/mountPoint ... ``` would this not work? Also, Ive never tried to go to the same folder, so I understand why this wouldn't work. – Ozzadar Mar 09 '16 at 12:10
  • The obvious thing doesn't work, sadly: docker: Error response from daemon: Duplicate mount point '/mount1' – David North Mar 09 '16 at 12:18
  • I'm also wondering this. – Sridhar Sarnobat Jul 28 '17 at 00:36

1 Answers1

1

One (probably obvious) workaround would be to install unionfs within the container and then unify all required partitions together with it:

docker run -v /path/to/d1:/mnt/d1 -v /path/to/d2:/mnt/d2
# and within docker container:
mkdir -p /mnt/joined
unionfs /mnt/d1=RO:/mnt/d2=RW /mnt/joined

But it is ugly and I hope there is any better option.

MarSoft
  • 3,555
  • 1
  • 33
  • 38