感谢您抽出时间阅读本篇文章!
我目前正在构建一个应用程序,其中使用了Python、Flask、Docker、Docker-compose和Ubuntu 18.04 LTS上的Postgres。以前,docker-compose build会成功,并且一切都按计划进行。但是,现在我切换到另一个Dockerfile,不再使用以前Dockerfile的缓存版本后,构建会出现以下错误:
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
我尝试了以下(Stackoverflow)帖子:
- "PermissionError: [Errno 13] Permission denied:'/usr/lib/python3.5/site-packages'"安装Django
- docker-compose, PermissionError: [Errno 13] Permission denied:'/manage.py'
- 如何在一步中更改文件夹及其子文件夹/文件的权限?
- pip install失败:OSError:目录上的[Errno 13]权限被拒绝
- docker-compose up&&docker-compose build:PostgreSQL错误
- https://phoenixnap.com/kb/fix-sub-process-usr-bin-dpkg-returned-error-code-1
我正在使用以下文件: 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
再次感谢您抽出时间阅读这个问题,如果需要任何其他信息(例如用于重现的最小可行 Flask 程序),请告诉我!