How Provide Nested Mount of Overlayfs

How provide nested mount of overlayfs

If you check dmesg output, you will see the kernel stating an attempt to exceed the max stacking depth:

overlayfs: maximum fs stacking depth exceeded

Indeed, the stacking depth is limited to 2, see the overlayfs dev branch:

  • #define FILESYSTEM_MAX_STACK_DEPTH
  • stacking depth check

If you want to go beyond this depth, you could try changing the constant and building your own kernel. However, bear in mind the risk of overflowing the stack (per the comments).

overlayfs inside docker container

Found something that worked! Mounting the workdir and upperdir as tmpfs does the trick for me.
Like so:

> mkdir /tmp/overlay
> mkdir /tmp/{low,merged}
> mount -t tmpfs tmpfs /tmp/overlay
> mkdir /tmp/overlay/{up,work}
> mount -t overlay overlay -o lowerdir=/tmp/low/,upperdir=/tmp/overlay/up/,workdir=/tmp/overlay/work/ /tmp/merged/

I'd still be interested in an explanation why creating an overlay w/o tmpfs fails within a docker container?

Can I mount docker host directory as copy on write/overlay?

Edit: Check @javabrett's comment:

Upvoted despite this solution having a sunset. See answer regarding overlay-upperdir-on-overlay being disabled on 4.8 kernels and newer.

See: https://stackoverflow.com/a/50917037/644504


This is what I do:

On the host:

Load the directory as read only.

docker run --privileged -v /path/on/host:/path/on/client-read-only:ro -it ubuntu /bin/bash

On the client:

On the client use OverlayFS over the read-only directory mounted from the host.

mount -t overlayfs none -o lowerdir=/path/on/client-read-only,upperdir=/path/on/client /path/on/client

Then use /path/on/client to read/write the files.

Edit: if you have a 3.18+ kernel on your host, you may prefer using this on the client:

mount -t overlay overlay -o lowerdir=/path/on/client-read-only,upperdir=/path/on/client,workdir=/path/on/client-workdir /path/on/client

Which isn't overlayfs. With overlayfs I had an issue regarding being unable to use rm. overlay solved this problem for me.



Related Topics



Leave a reply



Submit