docker-library / docker-library/postgres

postgres home directory, /var/lib/postgresql, owned by root again

Open
#1,420 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Shell
Stars
2.5k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

In 18+, /var/lib/postgresql is the mount target and still the postgres user's home directory. This brings back #274 (fixed by #277) when doing a bind mount on a new directory.

I have this issue again with v18. I started over with a fresh container and newly created volumes. This is my compose file:

services:

  db:
    image: postgres:18-alpine
    restart: unless-stopped
    environment:
      - POSTGRES_PASSWORD=redacted
      - TZ=Europe/Berlin
      - PGTZ=Europe/Berlin
    volumes:
      - /mnt/storage/postgres-data:/var/lib/postgresql
    ports:
      - "5432:5432"

Originally posted by @dkadioglu in #274

If the local directory for the bind mount (like /mnt/storage/postgres-data) doesn't exist before doing a docker compose up, then it will be automatically created by docker as root owned. If users need the .psql_history file, then they'll need to pre-create the directory locally (or chown/chmod after) with permissions such that the postgres user of the image can use it (uid/gid 70 in Alpine; uid/gid 999 in Debian); alternatively, they can run the image as a different user (e.g. user: 1000:1000) that already has permissions to access that directory on the host.


Now that 18 has moved the volume to /var/lib/postgresql/ instead of PGDATA, then it might make sense for us to chown or chmod it in the entypoint script so that the postgres user correctly owns or can at least use their home directory. 🤔 It could be a breaking change though, so we'll have to give it some thought.

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.

Research direction

Start with the entrypoint script and reproduce the bind-mount behavior using the compose file shown, including a newly created host directory. Determine how ownership and permissions differ for Alpine and Debian images; done means the postgres user can use its home directory without breaking existing volume behavior or introducing an unintended breaking change.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.