Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

pgAdmin container cannot write to /var/lib/pgadmin

ErrorPermission denied: '/var/lib/pgadmin/sessions'

Short answer

The pgAdmin image runs as user 5050 in group 0, not as root. A host folder mounted on /var/lib/pgadmin must be writable by that user. Change the folder owner to 5050:0, or on SELinux hosts and rootless Podman add the volume options the pgAdmin docs give.

  • Applies to pgAdmin 4 container image, Docker Engine 28, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Look at who owns the host folder you mounted. The pgAdmin docs say the process runs as UID 5050, so anything else owning the folder is the first suspect.

    ls -ldn ./pgadmin-data
  2. 2Match what you see, then jump to its fix

    1. 1ls -ldn shows root (0) or your own user id instead of 5050The host folder is owned by someone other than 5050Fix
    2. 2Ownership is correct and the error remains on Fedora, RHEL, Rocky or AlmaSELinux blocks the bind mountFix
    3. 3You run the image with rootless Podman and chown 5050 made no differenceRootless Podman maps user IDs differentlyFix

What does the error look like?

  • Permission denied: '/var/lib/pgadmin/sessions'

Cause 1 of 3

The host folder is owned by someone other than 5050

1Check

The docs state that pgAdmin runs as the pgadmin user (UID 5050) in group 0, and that mounted files must be readable and the session directory writable by that user.

docker exec pgadmin id

2Fix

Give the folder to that user and group, then start the container again.

sudo chown -R 5050:0 ./pgadmin-data
docker compose up -d

3Verify

The container stays up and the log shows no permission error.

docker logs --tail 20 pgadmin

Confirmed by pgadmin.org

Did this fix it?

Cause 2 of 3

SELinux blocks the bind mount

1Check

The pgAdmin docs say chown does not change SELinux labels. On a host with SELinux enforcing, the mount needs a label option.

getenforce

2Fix

Add Z (private label) or z (shared label) to the volume. The docs show the form with Z.

volumes:
  - ./pgadmin-data:/var/lib/pgadmin:Z

3Verify

Recreate the container and read the log.

docker compose up -d --force-recreate
docker logs --tail 20 pgadmin

Confirmed by pgadmin.org

Did this fix it?

Cause 3 of 3

Rootless Podman maps user IDs differently

1Check

In a rootless container, container user IDs map to a range of subordinate IDs on the host, so the host owner you set is not the one the container sees.

podman unshare ls -ldn ./pgadmin-data

2Fix

Add the U option so Podman changes ownership to match the container user. On SELinux hosts combine it with Z, as the docs do.

podman run -v ./pgadmin-data:/var/lib/pgadmin:Z,U docker.io/dpage/pgadmin4

3Verify

The container starts and pgAdmin answers on its port.

podman logs --tail 20 pgadmin

Confirmed by pgadmin.org

Did this fix it?

How do I stop it coming back?

  • Prefer a named volume for /var/lib/pgadmin when you do not need the files on the host.
  • Set ownership of any bind-mount folder before the first start.
  • Keep the image tag pinned and read the container notes when you upgrade.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Servers

A dev container port does not open in the browser when Docker runs on a remote host

If your application only accepts calls from localhost, it will reject connections from published ports

Three things usually break it: the app listens only on localhost inside the container, so published ports are rejected; you open the container port instead of the mapped localhost port VS Code shows; or you changed appPort or a Compose ports list and did not rebuild.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.