CentOS Stream 9
Sponsored Link

Docker : Use by common users2022/07/29

 
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.
# install Rootless package (generally it's already installed for dependency)

[root@dlp ~]#
dnf --enablerepo=docker-ce-stable -y install docker-ce-rootless-extras
# default name spaces number

[root@dlp ~]#
cat /proc/sys/user/max_user_namespaces

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

[root@dlp ~]#
cat /etc/subuid

cent:100000:65536
[root@dlp ~]#
cat /etc/subgid

cent: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 centos

[root@dlp ~]#
useradd redhat

[root@dlp ~]#
cat /etc/subgid /etc/subgid

cent:100000:65536
centos:165536:65536
redhat:231072:65536
cent:100000:65536
centos:165536:65536
redhat:231072:65536
[2] It's possible to run [docker] by common users.
# setup rootless mode by each user itself

[cent@dlp ~]$
dockerd-rootless-setuptool.sh install --skip-iptables

[INFO] Creating /home/cent/.config/systemd/user/docker.service
[INFO] starting systemd service docker.service
+ systemctl --user start docker.service

.....
.....

[INFO] Creating CLI context "rootless"
Successfully created context "rootless"

[INFO] Make sure the following environment variables are set (or add them to ~/.bashrc):

export PATH=/usr/bin:$PATH
export DOCKER_HOST=unix:///run/user/1000/docker.sock

# load displayed environment variables

[cent@dlp ~]$
export PATH=/usr/bin:$PATH

[cent@dlp ~]$
export DOCKER_HOST=unix:///run/user/1000/docker.sock
[cent@dlp ~]$
docker pull quay.io/centos/centos:stream9

[cent@dlp ~]$
docker images

REPOSITORY              TAG       IMAGE ID       CREATED        SIZE
quay.io/centos/centos   stream9   61674c24ebbf   33 hours ago   152MB

[cent@dlp ~]$
docker run quay.io/centos/centos:stream9 echo "run rootless containers"

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

[cent@dlp ~]$
ll ~/.local/share/docker

total 0
drwx--x--x. 4 cent cent 120 Apr  6 01:38 buildkit
drwx--x--x. 3 cent cent  20 Apr  6 01:38 containerd
drwx-----x. 3 cent cent  78 Apr  6 01:45 containers
drwx-----x. 6 cent cent 236 Apr  6 01:45 fuse-overlayfs
drwx------. 3 cent cent  28 Apr  6 01:38 image
drwxr-x---. 3 cent cent  19 Apr  6 01:38 network
drwx------. 4 cent cent  32 Apr  6 01:38 plugins
drwx------. 2 cent cent   6 Apr  6 01:38 runtimes
drwx------. 2 cent cent   6 Apr  6 01:38 swarm
drwx------. 2 cent cent   6 Apr  6 01:42 tmp
drwx------. 2 cent cent   6 Apr  6 01:38 trust
drwx-----x. 2 cent cent  25 Apr  6 01:38 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

[cent@dlp ~]$
docker run -t -d -p 1023:80 srv.world/centos-nginx /usr/sbin/nginx -g "daemon off;"

docker: Error response from daemon: driver failed programming external connectivity on endpoint thirsty_haibt (31bd9b8058f11434e0ffc33209359f35574699caf5bc27a7e9e1b90f53095351): Error starting userland proxy: error while calling 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 tcp 0.0.0.0:1023: bind: permission denied.

[cent@dlp ~]$
docker run -t -d -p 1024:80 srv.world/centos-nginx /usr/sbin/nginx -g "daemon off;"

[cent@dlp ~]$
docker ps

CONTAINER ID   IMAGE                    COMMAND                  CREATED         STATUS         PORTS                  NAMES
015c90358f47   srv.world/centos-nginx   "/usr/sbin/nginx -g …"   5 seconds ago   Up 4 seconds   0.0.0.0:1024->80/tcp   ecstatic_margulis
Matched Content