0

Context

I am exploring some options around overlayfs, in order to mount a directory inside a docker container with a "copy on write" behavior -- the container should be able to read any file from the host directory, but write actions should not reach the original directory.

The current options I am exploring involve creating the overlayfs on the host system before mounting it using docker run --volume $hostpath:$containerpath ....
(if I am missing a way to let docker handle the overlayfs directly, I am interested in being pointed in the right direction).

So right now, I am comparing sudo mount -t overlay ... with fuse-overlayfs ....

These actions are intended to be run on a developer's machine, and possibly on our CI systems,
we have no intention on using this to run processes in production.

So running sudo actions can be done, however it would be nice if I could figure out a way to run everything as the current user.

Situation

From my testing on my Ubuntu 22.10 system (linux 5.19) :

  • when I sudo mount ... an overlayfs on top of a lower directory, if a file in the lower directory is modified (and is not "hidden" by some file in the upper layer), the updated file is directly visible from the overlay fs

  • when I fuse-overlayfs ... the same directory, however, it looks like the files presented in the overlay system do not react to changes in the lower/ directory

Here is a script describing my test:
(fair warning: this script runs sudo mount and sudo umount actions, please read the code before executing on your machine ...)

$ cat test-overlay.sh
#!/bin/bash

# call:
#  - './test-overlay.sh fuse'   for 'fuse-overlayfs' test
#  - './test-overlay.sh'   for 'sudo mount -t overlay' test
#  - './test-overlay.sh umount'  to unmount the filesystem if any mount is left over

set -e


cd $(dirname "$0")

mkdir -p test
cd test

if [[ "$1" == "u" || $1 == "umount" ]]; then
    echo "=== unmounting test/overlay"
    sudo umount overlay
    exit $?
fi

echo "=== setting up test directory:"
echo "    running: 'sudo umount overlay' ..."
sudo umount overlay 2> /dev/null || true

sudo rm -rf overlay upper work lower

mkdir overlay upper work lower

echo "foo - first line" >> lower/foo
echo "bar - first line" >> lower/bar


if [ "$1" = "fuse" ]; then
    echo "=== mounting using fuse-ovelayfs ..."
    fuse-overlayfs -o lowerdir=$PWD/lower,workdir=$PWD/work,upperdir=$PWD/upper $PWD/overlay
else
    echo "=== mounting using sudo mount ..."
    echo "    running: 'sudo mount -t overlay ...'"
    sudo mount -t overlay -o lowerdir=$PWD/lower,workdir=$PWD/work,upperdir=$PWD/upper overlayfs $PWD/overlay
fi

echo "=== expecting 1 line in overlay/foo"

if [ $(wc -l < overlay/foo) -ne 1 ]; then
    echo "  failed: got $(wc -l < overlay/foo) lines instead"
fi

echo "foo: 2nd line" >> lower/foo

echo "=== expecting 2 line in overlay/foo"

if [ $(wc -l < overlay/foo) -ne 2 ]; then
    echo "  failed: got $(wc -l < overlay/foo) lines instead"
fi

# comment next line if you want to keep the filesystem mounted and inspect it:
echo "    running: 'sudo umount overlay' ..." && sudo umount overlay

Question

Are there some extra options I should set when using fuse-overlayfs to have the overlay layer behave as mount -t overlay ?

namely :

if a file is not touched or modified in the upper layer, directly see the modifications made on the lower layer visible from the overlay filesystem

LeGEC
  • 46,477
  • 5
  • 57
  • 104

0 Answers0