1

I have docker-compose.yml with next describe of database

  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

My problem is that directory pg-data creates with privileges and when I try to rebuild my container I get an error

docker-compose up -d --build
Traceback (most recent call last):
  File "bin/docker-compose", line 6, in <module>
  File "compose/cli/main.py", line 72, in main
  File "compose/cli/main.py", line 128, in perform_command
  File "compose/cli/main.py", line 1077, in up
  File "compose/cli/main.py", line 1073, in up
  File "compose/project.py", line 548, in up
  File "compose/service.py", line 351, in ensure_image_exists
  File "compose/service.py", line 1106, in build
  File "site-packages/docker/api/build.py", line 160, in build
  File "site-packages/docker/utils/build.py", line 30, in tar
  File "site-packages/docker/utils/build.py", line 49, in exclude_paths
  File "site-packages/docker/utils/build.py", line 214, in rec_walk
  File "site-packages/docker/utils/build.py", line 184, in rec_walk
PermissionError: [Errno 13] Permission denied: '/home/ubuntu/PhpstormProjects/fntr/docker/postgres/pg-data'
[8296] Failed to execute script docker-compose
Viktor
  • 1,532
  • 6
  • 22
  • 61
  • Does this answer your question? [Docker and --userns-remap, how to manage volume permissions to share data between host and container?](https://stackoverflow.com/questions/35291520/docker-and-userns-remap-how-to-manage-volume-permissions-to-share-data-betwee) – ezkl Feb 26 '20 at 14:45
  • I have no problems with other containers. Only with postgres – Viktor Feb 26 '20 at 14:53

1 Answers1

-1

as said the error is just a write permission issue

First confirm that the USER that start docker-compose up -d --build got right permission on folder /home/ubuntu/PhpstormProjects/fntr/docker/postgres/pg-data

Then docker-compose.yml

database:
    container_name: k4fntr_database
    build: ./docker/postgres
    restart: always
    privileged: true    # <-- Add this
    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:rw" # <-- add :rw at the end
    networks:
      - backend-network
J-Jacques M
  • 978
  • 6
  • 16