Docker : Use by common users2025/08/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. |
|
# install Rootless package (generally it's already installed for dependency) [root@dlp ~]# dnf --enablerepo=docker-ce-stable -y install docker-ce-rootless-extras # sub UID/GID mapping file # 524288 to 589823 (524288 + 65536 - 1) UID are used for running processes in containers on [cent] user [root@dlp ~]# cat /etc/subuid cent:524288:65536 [root@dlp ~]# cat /etc/subgid cent:524288:65536 # when added new users, sub UID/GID are also added # n=0, n++ # [start UID/GID = 524288 + (65536 * n)] # [end UID/GID = (start UID/GID) + 65536 - 1] [root@dlp ~]# useradd fedora [root@dlp ~]# useradd redhat [root@dlp ~]# cat /etc/subgid /etc/subgid cent:524288:65536 fedora:589824:65536 redhat:655360:65536 cent:524288:65536 fedora:589824:65536 redhat:655360: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] 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/bin:$PATH [INFO] Some applications may require the following environment variable too: 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
docker pull quay.io/centos/centos:stream10 [cent@dlp ~]$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE quay.io/centos/centos stream10 f411d33ff55a About an hour ago 307MB
[cent@dlp ~]$
docker run quay.io/centos/centos:stream10 echo "run rootless containers" run rootless containers # containers related files are located under the [$HOME/.local] directory [cent@dlp ~]$ ll ~/.local/share/docker total 8 drwx--x--x. 3 cent cent 123 Aug 8 15:48 buildkit drwx--x--x. 3 cent cent 20 Aug 8 15:48 containerd drwx--x---. 3 cent cent 78 Aug 8 15:51 containers -rw-------. 1 cent cent 36 Aug 8 15:48 engine-id drwx--x---. 6 cent cent 4096 Aug 8 15:51 fuse-overlayfs drwx------. 3 cent cent 28 Aug 8 15:48 image drwxr-x---. 3 cent cent 19 Aug 8 15:48 network drwx------. 3 cent cent 17 Aug 8 15:48 plugins drwx------. 2 cent cent 6 Aug 8 15:48 runtimes drwx------. 2 cent cent 6 Aug 8 15:48 swarm drwx------. 2 cent cent 6 Aug 8 15:50 tmp drwx-----x. 2 cent cent 25 Aug 8 15:48 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 -dt -p 1023:80 quay.io/centos/centos:stream10 bash docker: Error response from daemon: failed to set up container networking: driver failed programming external connectivity on endpoint beautiful_swanson (824d6d30a0ace704b5b75bcf5e13d8760eecde75f424f6f82f9133971d5cef8a): 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[cent@dlp ~]$ docker run -dt -p 1024:80 quay.io/centos/centos:stream10 bash [cent@dlp ~]$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f79e4880842e quay.io/centos/centos:stream10 "bash" 5 seconds ago Up 4 seconds 0.0.0.0:1024->80/tcp, [::]:1024->80/tcp reverent_northcutt |
| Sponsored Link |