Search code examples
djangodockerpipelinedocker-volumebitbucket-pipelines

Bitbucket pipeline docker volume permissions at recreating containers


I have deployed django app with docker container. Source code of the app is on the Bitbucket repository. Now I want to setup pipeline for master branch which is intended to make deployment automatic on merge. Problematic part of the pipeline script is below:

docker-compose up --build -d

Above line resuts with error that says:

Permission denied: '/path/to/docker/volume/pgdb'

My docker-compose file section related to postgres is below:

  postgres:
    container_name:  arw-postgres
    image:           postgres:11
    ports:
      - 5432:5432
    volumes:
      - ./pgdb:/var/lib/postgresql/data
    env_file: .env

The above specified docker-compose command runs normally with sudo privilege. Actually, I can connect to remote host with root user and can run this command. But I don't want to expose my root user's credentials. How can I recreate my docker container without sudo privileges?


Solution

  • The problem here was non-existence of .dockerignore file. I simply added .dockerignore file with the content pgdb at the same level with Dockerfile. This file avoids copying of protected pgdb folder to docker container, so no permission error occurs.