How to mount a directory into a container, where changes in the container don't propagate to host?

I’ve been experimenting with volumes/mounts/tmpfs and storage drivers and i’ve yet to figure out how to do this.

For example, mount /home from the host to /home in the container. If I create a new file /home/foo in the container, no file would be created on the host.

Anyone know how to do this? Thanks!

Figured this out. I had to create an overlay mount with my homedir as the lower and a /tmp dir as the upper and mounted the overlay into the container as /home. :slight_smile:

Could you extend your solution with the actual commands? That would be more informative to a lot of users, I think.

1 Like

For sure!
First I created an overlay mount like so:

mkdir -p /tmp/test/upper /tmp/test/workdir /tmp/test/overlay
mount \
    -t overlay \
    -o \
    workdir=/tmp/test/workdir \
    none \

At this point /tmp/test/overlay is a combined view of /home and /tmp/test/upper. Mounting that directory into the container as a volume means that any writes will happen in /tmp/test/upper but inside the container it’ll look like the writes are to /home.

podman run -it --rm \
    --group-add=wheel \
    --hostname=toybox \
    --ipc=host \
    --name=test \
    --network=host \
    --no-hosts \
    --pid=host \
    --privileged \
    --security-opt label=disable \
    --uidmap 1000:0:1 \
    --uidmap 0:1:1000 \
    --uidmap 1001:1001:64536 \
    --user root:root \
    --storage-driver=overlay \
    --volume /tmp/test/overlay:/home/grant
    fedora bash
1 Like