I have configured Podman as user as I describe in this post
In my dockerfile, I am going to great pains to absolutely ensure that the directory is owned by the user in question and have gone so far as to hardcode the values to be absolutely sure that it isn't a problem with environment variables while further deleting any group or user with node and then recreating them with that specific ID just to be extra extra certain:
ARG USER_ID 1000
ARG GROUP_ID 1000
ARG GROUPNAME node
ARG USERNAME node
# getent group ${GROUP_ID} - Get the name of the group. Ex: `somegroup:x:999:`. This makes sure the group exists
# echo groupdel by-id ${GROUP_ID} - This is just there to tell the user what we're doing
# groupdel $(getent group ${GROUP_ID} | cut -d: -f1) - Gets the group string as above (`somegroup:x:999:`)
# and then passes it into `cut -d: -f1` which will grab the `somegroup` part and pass that into groupdel
# ||: The || is the or operator and : is the null operator. This just has the effect of ensuring the line
# returns with "success" rather than failure in the event the group doesn't exist
RUN (getent group ${GROUP_ID} && (echo groupdel by-id ${GROUP_ID}; groupdel $(getent group ${GROUP_ID} | cut -d: -f1))) ||:
RUN (getent group ${GROUPNAME} && (echo groupdel ${GROUPNAME}; groupdel ${GROUPNAME})) ||:
RUN (getent passwd ${USERNAME} && (echo userdel ${USERNAME}; userdel -f ${USERNAME})) ||:
RUN groupadd -g ${GROUP_ID} ${GROUPNAME}
RUN useradd -l -u ${USER_ID} -g ${GROUPNAME} ${USERNAME}
WORKDIR /home/node/app
RUN mkdir /patches
RUN chown node:node /patches
This still didn't work, so in my build in docker-compose I further specified, explicitly, the permissions:
build:
dockerfile: podman-build/Dockerfile.patches_backend
args:
USER_ID: ${USER_ID:-1000}
GROUP_ID: ${GROUP_ID:-1000}
USERNAME: node
GROUPNAME: node
I don't know what else I'm missing, the UID/GID is correct in the container, the permissions of the folder outside the container are UID/GID=1000 as expected:

but this volume mount:
volumes:
- type: bind
source: repos/xml
target: /patches/xml
still stubbornly mounts in as root with UID/GID=0. I cannot for the life of me figure out where else it could be getting these permissions.
The solution in 2024, with the caveat that the user seen from the host will be the one from inside the container, which means that the host will have readonly right, is to add :U as a mount option at the end of the --volume argument, like in:
podman run -ti --volume /tmp/testmount/:/home/ubuntu/mountpoint:U --rm --name mount_test localhost/testmount:latest
This allows to mount a folder on the host inside the container, and to have the mounted content appear as owned by the container user, not the container root.
FROM ubuntu:24.04
USER ubuntu
WORKDIR /home/ubuntu/mountpoint
CMD /bin/bash
mkdir /tmp/testmount && touch /tmp/testmount/hello
podman build -t testmount:latest .
:U at the end of the --volume option!podman run -ti --volume /tmp/testmount/:/home/ubuntu/mountpoint:U --rm --name mount_test localhost/testmount:latest
for example:
$ podman run -ti --volume /tmp/testmount/:/home/ubuntu/mountpoint:U --rm --name mount_test localhost/testmount:latest
ubuntu@e96984ec46bd:~/mountpoint$ ls -lrth
total 0
-rw-rw-r-- 1 ubuntu ubuntu 0 Oct 31 08:27 hello
ubuntu@e96984ec46bd:~/mountpoint$ exit
exit
$
:U option, the volume is mounted as root inside the container:$ podman run -ti --volume /tmp/testmount/:/home/ubuntu/mountpoint --rm --name mount_test localhost/testmount:latest
ubuntu@4c8d3ebb997b:~/mountpoint$ ls -lrth
total 0
-rw-rw-r-- 1 root root 0 Oct 31 08:27 hello
ubuntu@4c8d3ebb997b:~/mountpoint$ exit
Edit: the owner seen from the host will be the "unknown" container user, so the host will have readonly rights. I guess there can be ways to change rights / add and edit group properties on the host to make this work better, but I have not looked into this.
This tutorial does a great job of explaining the problem. You have two options:
podman unshare which will let you run commands in the same namespace as containers.podman unshare isn't great. The way that it works is you determine what UID is employed by the container and then you use unshare to set the ownership of the directory on the host filesystem to use that namespace. Problem is this requires you to change the owner on the host system which is rarely desirable and causes permissions issues.
The second approach is a lot better, albeit not from a security perspective - run as root inside the container and then mount the container with either :Z or :z. I'll let ChatGPT explain the difference between the two (it does a good job):
Ex:
podman run -it --rm --name nexus2 \
-v /home/tom/myshares/nexus2:/sonatype-work:Z \
-u root \
sonatype/nexus /bin/sh
Hope this helps other people!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With