Cannot run container as non-root user

Open
#532 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
docker, postgresql
Domain
databases, devops

Research direction

Start with the provided Quadlet service, containers.conf, and the systemctl --user start postgres command on RHEL 9. Reproduce the initdb: error: cannot be run as root failure for the PostgreSQL 13/14/15 images and trace how the configured User=serviceuser is applied. Done means the container starts successfully as a non-root user.

Written by the indexing model from the issue text.

Description

Container platform

Podman/Docker

Version

rhel9/postgres-13 and postgres-15. maybe 14 too..

OS version of the container image

RHEL 9

Bugzilla, Jira

No response

Description

Podman is unable to run the container with quadlet as non-root user.

I have the following systemd-file:

## Quadlet Postgres Container Service File

[Unit]
Description=Postgres Container

[Container]
Image=repo/rhel9/postgresql-15:1-28
Volume=/opt/service/postgres/data:/var/lib/pgsql/data
User=serviceuser
ContainerName=postgres
Environment=POSTGRESQL_USER=serviceuser
Environment=POSTGRESQL_PASSWORD=pw
Environment=POSTGRESQL_DATABASE=service
Environment=POSTGRESQL_ADMIN_PASSWORD=adminpw
PublishPort=5432:5432

[Service]
WorkingDirectory=/opt/home/serviceuser
Restart=always
Environment=REGISTRY_AUTH_FILE=/opt/home/serviceuser/auth_zar.json

My containers.conf

.config/containers/containers.conf

# Please refer to containers.conf(5) for details of all configuration options.
# Precedence order:
#  1. /usr/share/containers/containers.conf
#  2. /etc/containers/containers.conf
#  3. $HOME/.config/containers/containers.conf (Rootless containers ONLY)

[containers]

cgroupns = "private"
cgroups = "enabled"
cgroup_manager = "systemd"

ipcns = "private"
netns = "private"
pidns = "private"
utsns = "private"

tz = "local"

rootless_networking = "slirp4netns"

after starting as non-root:

#systemctl --user start postgres
...

Started Postgres Container.
Warning: Can't detect cpu quota from cgroups
Warning: Can't detect cpuset size from cgroups
initdb: error: cannot be run as root
initdb: hint: Please log in (using, e.g., "su") as the (unprivileged) user that will own the server process.
Reproducer

No response

Dominant language
PLpgSQL
Stars
178
Forks
220
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sclorg/postgresql-container

All issues in sclorg/postgresql-container

Similar issues

More Databases issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.