Skip to content

Instantly share code, notes, and snippets.

@detunized
Created September 4, 2017 11:02
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save detunized/7c8fc4c37b49c5475e68ef9574587eee to your computer and use it in GitHub Desktop.
Save detunized/7c8fc4c37b49c5475e68ef9574587eee to your computer and use it in GitHub Desktop.
Mount a read-only folder inside a Docker container with OverlayFS on top
# On the host to run the container
docker run --privileged -i -t -v ~/host-folder-to-mount:/root/folder-ro:ro ubuntu
# Inside the container
# Need to create the upper and work dirs inside a tmpfs.
# Otherwise OverlayFS complains about AUFS folders.
mkdir -p /tmp/overlay && \
mount -t tmpfs tmpfs /tmp/overlay && \
mkdir -p /tmp/overlay/{upper,work} && \
mkdir -p /root/folder && \
mount -t overlay overlay -o lowerdir=/root/folder-ro,upperdir=/tmp/overlay/upper,workdir=/tmp/overlay/work /root/folder
@daniel-ciaglia
Copy link

You don't have to run docker with full --privileged permissions. Just --cap-add=SYS_ADMIN seems to be sufficient.

@lemonlatte
Copy link

Super helpful. Thanks so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment