Thanks for taking the time to read this post!
I'm currently building an application that makes use of Python, Flask, Docker, Docker-compose and Postgres on Ubuntu 18.04 LTS. Previously, docker-compose build would succeed and everything was working according to plan. However, now that I switched to another Dockerfile, and I'm not using the cached version of the previous Dockerfile anymore, the build breaks with the following error:
PermissionError: [Errno 13] Permission denied: '/usr/lib/python3.7/__pycache__/__future__.cpython-37.pyc.140409285875056'
dpkg: error processing package python3.7-minimal (--configure):
installed python3.7-minimal package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
python3.7-minimal
I have tried the following (Stackoverflow) posts:
- "PermissionError: [Errno 13] Permission denied: '/usr/lib/python3.5/site-packages'" installing Django
- docker-compose , PermissionError: [Errno 13] Permission denied: '/manage.py'
- How to change permissions for a folder and its subfolders/files in one step?
- pip install failing with: OSError: [Errno 13] Permission denied on directory
- docker-compose up && docker-compose build : error with PostgreSQL
- https://phoenixnap.com/kb/fix-sub-process-usr-bin-dpkg-returned-error-code-1
but alas, to no avail.
I'm using the following files:
Dockerfile.prod
# pull official base image
FROM python:3.9.0-slim-buster
# set working directory
WORKDIR /usr/src/app
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV FLASK_ENV production
ENV APP_SETTINGS src.config.ProductionConfig
# install system dependencies
RUN apt-get update \
&& apt-get -y install netcat gcc postgresql\
&& apt-get clean
# add and install requirements
COPY ./requirements.txt .
RUN pip install -r requirements.txt
# add app
COPY . .
# add and run as non-root user
RUN adduser --disabled-password myuser
USER myuser
# run gunicorn
CMD gunicorn --bind 0.0.0.0:$PORT manage:app
docker-compose.yml
version: '3.8'
services:
api:
build:
context: .
dockerfile: Dockerfile.prod
entrypoint: ['/usr/src/app/entrypoint.sh']
volumes:
- .:/user/src/app
ports:
- 5004:5000
environment:
- FLASK_ENV=development
- APP_SETTINGS=src.config.DevelopmentConfig
- DATABASE_URL=postgresql://postgres:postgres@api-db:5432/api_dev
- DATABASE_TEST_URL=postgresql://postgres:postgres@api-db:5432/api_test
depends_on:
- api-db
api-db:
build:
context: ./src/db
dockerfile: Dockerfile
expose:
- 5432
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
./src/db/Dockerfile
FROM postgres:13-alpine
ADD create.sql /docker-entrypoint-initdb.d
Thanks once again for taking the time to read through this question, and if any additional information is required (e.g. a minimum viable Flask program to reproduce) please let me know!