Docker traditionally ran as the root
user. Users who wanted to run docker containers needed to be given sudo
access and use sudo docker
, or be added to the docker
group, so they could run docker without typing sudo
first. In both cases, they were running docker with root privileges. This is considered a bad security practice, because it effectively grants root host privileges to all docker users. However, namespaces and control groups where not as mature as they are now, and no better alternative was available.
However today docker offers the possibility to run in rootless mode. Podman runs rootless by design.
Podman 4.7 and above includes an extended syntax for --uidmap
and --gidmap
that makes it straightforward to map additional groups. This feature was contributed by a rocker user, so you are encouraged to try it!
Running a container rootless does not mean that the container does not have any root-like capabilities, it means that the container engine does not run as root. For most rocker-related projects, running rootless is a security advantage.
1 Who am I?
At the host:
Terminal
whoami
# sergio
In the container:
Terminal
podman run --rm docker.io/rocker/rstudio whoami
# root
2 Using apt-get inside a rootless container
It is perfectly possible to run apt-get
commands on a rootless container, because it just modifies files inside the container.
At the host:
Terminal
apt-get update
# Reading package lists... Done
# E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
In the container:
Terminal
podman run --rm docker.io/rocker/rstudio apt-get update
# Get:1 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
# ...
# Fetched 26.8 MB in 6s (4,750 kB/s)
# Reading package lists...
3 Modifying files
You can bind mount the /etc/
directory (e.g. using -v /etc:/hostetc
) but you won’t be able to modify most of its files, since you are not allowed to do that when you are outside the container.
At the host:
Terminal
touch /etc/try-creating-a-file
# touch: cannot touch '/etc/try-creating-a-file': Permission denied
In the container: Rootless means no additional host permissions
Terminal
podman run --rm -v /etc/:/hostetc docker.io/rocker/rstudio \
touch /hostetc/try-creating-a-file# touch: cannot touch '/hostetc/try-creating-a-file': Permission denied
However, you can modify the files within the container:
Terminal
podman run --rm docker.io/rocker/rstudio touch /etc/try-creating-a-file
And files from mounted volumes, assuming you have the permissions where they are mounted at the host:
Terminal
podman run \
--rm \
--volume "$HOME/workdir:/workdir" \
docker.io/rocker/rstudio touch /workdir/try-creating-a-filels "$HOME/workdir/try-creating-a-file"
rm "$HOME/workdir/try-creating-a-file"
Your user in the host is mapped to the root
user in the container.
4 Port binding
You can’t bind your container to host ports lower than 1024, since those are reserved to root (or to be precise reserved to processes with CAP_NET_BIND_SERVICE
capability set).
Terminal
podman run --rm -p 80:8787 docker.io/rocker/rstudio
# Error: rootlessport cannot expose privileged port 80, you can add
# 'net.ipv4.ip_unprivileged_port_start=80' to /etc/sysctl.conf (currently 1024),
# or choose a larger port number (>= 1024):
# listen tcp 0.0.0.0:80: bind: permission denied
However larger port numbers work perfectly fine:
Terminal
podman run --rm -p 8787:8787 docker.io/rocker/rstudio