Data directory "/var/lib/postgresql/data" has invalid permissions

I am new to Docker and have learnt a couple of commands. I am trying to run a postgres database container via Docker and after pulling postgres with
docker pull postgres

I proceeded to running a container the container with the command:
docker run -d -p 3005:3005 --name postgres-wikijs-3005 --restart unless-stopped -e "DB_TYPE=postgres" -e "DB_HOST=postgres-wikijs-3005" -e "DB_PORT=5432" -e "DB_USER=wikijs" -e "DB_PASS=wikijs" -e "DB_NAME=postgres-wikijs-3005" requarks/wiki:2

But the container automatically stops running a few seconds after it starts with an error:

The files belonging to this database system will be owned by user “postgres”.
This user must also own the server process.

The database cluster will be initialized with locale “en_US.utf8”.
The default database encoding has accordingly been set to “UTF8”.
The default text search configuration will be set to “english”.

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/data … ok
creating subdirectories … ok
selecting dynamic shared memory implementation … posix
selecting default max_connections … 20
selecting default shared_buffers … 400kB
selecting default time zone … Etc/UTC
creating configuration files … ok
2021-01-15 17:11:36.428 UTC [83] FATAL: data directory “/var/lib/postgresql/data” has invalid permissions
2021-01-15 17:11:36.428 UTC [83] DETAIL: Permissions should be u=rwx (0700) or u=rwx,g=rx (0750).
child process exited with exit code 1
initdb: removing contents of data directory “/var/lib/postgresql/data”
running bootstrap script …

How can i access the “/var/lib/postgresql/data” to modify the permissions via command line? I can’t seem to find that path in my local drive.

Thanks!

Resolved the issue by accessing bash terminal and enabling permissions with ‘chmod’ commands

I met the same quesions, there is enabling permissions on host path or container path?

Is there a common solution for this problem. I loaded a compose file and have this problem

services:
  db:
    container_name: "x_dev_postgres"
    image: docker-hub-remote.x.tech.rz.db.de/postgres:15.7-alpine
    networks:
      - mynetwork
    ports:
      - "5432:5432"
    restart: always
    environment:
      POSTGRES_USER: root
      POSTGRES_PASSWORD: xxx
      POSTGRES_DB: x
    volumes:
      - "${POSTGRES_VOLUME_DIR:-./volume/postgres}:/var/lib/postgresql/data"

But the permissions are looking good I would say.


Is the original reason for the occurrence of this annoying behavior known?

The “Where to Store Data” section in the README.md states it partialy:

  • Create a data directory on the host system (outside the container) and mount this to a directory visible from inside the container. This places the database files in a known location on the host system, and makes it easy for tools and applications on the host system to access the files. The downside is that the user needs to make sure that the directory exists, and that e.g. directory permissions and other security mechanisms on the host system are set up correctly.

The relevant part: “directory permissions and other security mechanisms on the host system are set up correctly.”

The README.md could at least mention that the default uid:gid is 70:70 (I looked it up in the Dockerfile for the 15.x tag you used). With docker-ce, the owner of the host folder must be the uid 70.

I really hope the image tag you used is just an example, as the image for this specific tag has 3 critical and 41 high findings.

It was a new Docker Desktop installation and in SettingsUse the WSL 2 based engine was not selected. With WSL2 it seems the problem don’t exist anymore

1 Like