Ubuntu 26.04

Docker : Use by common users2026/05/08

 

It's possible to use Docker containers by common users.

[1] By default, sub UID/GID that are used on user name spaces are assigned to run containers.
root@dlp:~#
apt -y install rootlesskit

root@dlp:~#
ln -s /usr/bin/docker /usr/share/docker.io/contrib/docker
# default name spaces number

root@dlp:~#
cat /proc/sys/user/max_user_namespaces

61617
# sub UID/GID mapping file
# 100000 to 165535 (100000 + 65536 - 1) UID are used for running processes in containers on [ubuntu] user

root@dlp:~#
cat /etc/subuid

ubuntu:100000:65536
root@dlp:~#
cat /etc/subgid

ubuntu:100000:65536
# when added new users, sub UID/GID are also added
# n=0, n++
# [start UID/GID = 100000 + (65536 * n)]
# [end UID/GID = (start UID/GID) + 65536 - 1]

root@dlp:~#
useradd resolute

root@dlp:~#
useradd raccoon

root@dlp:~#
cat /etc/subgid /etc/subgid

ubuntu:100000:65536
resolute:165536:65536
raccoon:231072:65536
ubuntu:100000:65536
resolute:165536:65536
raccoon:231072:65536

root@dlp:~#
cp /usr/share/docker.io/contrib/dockerd-rootless-setuptool.sh /usr/local/bin/
[2] It's possible to run [docker] by common users.
# setup rootless mode by each user itself

ubuntu@dlp:~$
export PATH=/usr/share/docker.io/contrib:$PATH

ubuntu@dlp:~$
dockerd-rootless-setuptool.sh install --skip-iptables

[INFO] Creating /home/ubuntu/.config/systemd/user/docker.service
[INFO] starting systemd service docker.service
+ systemctl --user start docker.service
+ sleep 3
+ systemctl --user --no-pager --full status docker.service

.....
.....

[INFO] Installed docker.service successfully.
[INFO] To control docker.service, run: `systemctl --user (start|stop|restart) docker.service`
[INFO] To run docker.service on system startup, run: `sudo loginctl enable-linger ubuntu`

[INFO] Creating CLI context "rootless"
Successfully created context "rootless"
[INFO] Using CLI context "rootless"
Current context is now "rootless"

[INFO] Make sure the following environment variable(s) are set (or add them to ~/.bashrc):
export PATH=/usr/share/docker.io/contrib:$PATH

[INFO] Some applications may require the following environment variable too:
export DOCKER_HOST=unix:///run/user/1000/docker.sock

ubuntu@dlp:~$
export PATH=/usr/bin:$PATH

ubuntu@dlp:~$
export DOCKER_HOST=unix:///run/user/$(id -u)/docker.sock
ubuntu@dlp:~$
docker pull ubuntu

ubuntu@dlp:~$
docker images

IMAGE           ID             DISK USAGE   CONTENT SIZE   EXTRA
ubuntu:latest   f3d28607ddd7        160MB         45.3MB

ubuntu@dlp:~$
docker run ubuntu echo "run rootless containers"

run rootless containers
# containers related files are located under the [$HOME/.local] directory

ubuntu@dlp:~$
ll ~/.local/share/docker

total 52
drwx--x--- 12 ubuntu ubuntu 4096 May  8 01:27 ./
drwx--x--x  3 ubuntu ubuntu 4096 May  8 01:26 ../
drwx--x--x  4 ubuntu ubuntu 4096 May  8 01:26 buildkit/
drwx------  3 ubuntu ubuntu 4096 May  8 01:26 containerd/
drwx--x---  3 ubuntu ubuntu 4096 May  8 01:27 containers/
-rw-------  1 ubuntu ubuntu   36 May  8 01:26 engine-id
drwxr-x---  3 ubuntu ubuntu 4096 May  8 01:26 network/
drwx------  3 ubuntu ubuntu 4096 May  8 01:26 plugins/
drwx--x---  3 ubuntu ubuntu 4096 May  8 01:27 rootfs/
drwx------  2 ubuntu ubuntu 4096 May  8 01:26 runtimes/
drwx------  2 ubuntu ubuntu 4096 May  8 01:26 swarm/
drwx------  2 ubuntu ubuntu 4096 May  8 01:26 tmp/
drwx-----x  2 ubuntu ubuntu 4096 May  8 01:26 volumes/

# for port mapping,
# it's impossible to use less than [1024] ports on Host machine by common users
# possible to use over [1024] ports

ubuntu@dlp:~$
docker run -dt -p 1023:80 ubuntu bash

13f86e05f53a31552a55dc97cbd09a5100f176b10f6adab4ffd0a12b6d82414d
docker: Error response from daemon: failed to set up container networking: driver failed programming external connectivity on endpoint great_rhodes (d6f10258ff61a9616d5876a46c7c5233d982580eba5200ae029d66a156ecbb04): error while calling RootlessKit PortManager.AddPort(): cannot expose privileged port 1023, you can add 'net.ipv4.ip_unprivileged_port_start=1023' to /etc/sysctl.conf (currently 1024), or set CAP_NET_BIND_SERVICE on rootlesskit binary, or choose a larger port number (>= 1024): listen tcp4 0.0.0.0:1023: bind: permission denied

Run 'docker run --help' for more information

ubuntu@dlp:~$
docker run -dt -p 1024:80 ubuntu bash

ubuntu@dlp:~$
docker ps

CONTAINER ID   IMAGE     COMMAND   CREATED         STATUS         PORTS                                     NAMES
96c4b5218881   ubuntu    "bash"    3 seconds ago   Up 3 seconds   0.0.0.0:1024->80/tcp, [::]:1024->80/tcp   exciting_golick
Matched Content