Viktor
Viktor

Reputation: 1692

Why postgres container changes folder`s owner (docker-compose)

My docker-compose.yml is

  database:
    container_name: k4fntr_database
    build: ./docker/postgres
    restart: always
    environment:
      ENV: ${APP_ENV}
      TESTING_DB: ${DB_DATABASE_TESTING}
      POSTGRES_DB: ${DB_DATABASE}
      POSTGRES_USER: ${DB_USERNAME}
      POSTGRES_PASSWORD: ${DB_PASSWORD}
    ports:
      - "15432:5432"
    volumes:
    - ./docker/postgres/pg-data:/var/lib/postgresql/data
    networks:
      - backend-network

and my Dockerfile is

FROM postgres:10.5-alpine

COPY /docker-entrypoint-initdb.d/ /docker-entrypoint-initdb.d/

RUN chmod 0755 -R /docker-entrypoint-initdb.d/

I have a problem when I run

docker-compose up -d --build

a folder which is called pg-data is created with wrong permissions from user "70" and group "root"

enter image description here

This permissions don't let me to do any things such as look inside the folder. In addition, when I try to rebuild the container with

docker-compose up -d --build

I get an error

PermissionError: [Errno 13] Permission denied: '/home/ubuntu/PhpstormProjects/fntr/docker/postgres/pg-data' [5262] Failed to execute script docker-compose

I run docker-compose as user ubuntu:ubuntu.

The situation was changed a little bit when I created folder BEFORE run

docker-compose up -d --build

In this case the folder has group "ubuntu" but the owner is still "70"

enter image description here

but there is no some effects and all problems are exists

Upvotes: 0

Views: 3146

Answers (1)

Palash Goel
Palash Goel

Reputation: 664

Postgres run an entrypoint file when a container is started.

https://github.com/docker-library/postgres/blob/master/10/docker-entrypoint.sh#L36

This is the function that changes the permission of the directory inside docker container. Since this directory is mounted on the host file-system too, the permissions are reflected there.

On your system, check the user currently mapped to uid-999. You can have a clue from there. Avoid posting /etc/passwd or /etc/shadow file here

You need to pass User in docker-compose

See https://hub.docker.com/_/postgres -> Arbitrary --user Notes

Upvotes: 1

Related Questions