2

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

2
  • Please add Dockerfile for the image. Most likely, the container is running as user 70 and is creating a folder using this. Inside the container, user 70 is resolvable through /etc/passwd but it is not resolvable on the host machine. Commented Feb 27, 2020 at 12:08
  • I have dockerfile but there aren`t some interesting things FROM postgres:10.5-alpine COPY /docker-entrypoint-initdb.d/ /docker-entrypoint-initdb.d/ Commented Feb 27, 2020 at 12:16

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

cat /etc/passwd | grep 999 guest-sdklnd:x:999:999:Guest:/tmp/guest-sdklnd:/bin/bash
I can't understand. Postgres doing that inside the container, but I have problem with my filesystem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.