PermissionError:[WinError 5]访问被拒绝:[4776]运行docker-compose up时无法执行脚本docker-compose

时间:2020-10-15 12:28:09

标签: python windows docker docker-compose permissions

我构建了一个测试应用程序,以更好地了解FastAPI和sqlalchemy的概念 我想成为一个能够提供docker-compose.yml的应用程序,该程序可以仅用于运行我的解决方案 做docker-compose up

但是我得到了

Building al_test
Traceback (most recent call last):
  File "docker-compose", line 3, in <module>
  File "compose\cli\main.py", line 67, in main
  File "compose\cli\main.py", line 126, in perform_command
  File "compose\cli\main.py", line 1070, in up
  File "compose\cli\main.py", line 1066, in up
  File "compose\project.py", line 615, in up
  File "compose\service.py", line 362, in ensure_image_exists
  File "compose\service.py", line 1125, 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 214, in rec_walk
  File "site-packages\docker\utils\build.py", line 184, in rec_walk
PermissionError: [WinError 5] Отказано в доступе: '\\\\?\\C:\\$Recycle.Bin\\S-1-5-18'
[4776] Failed to execute script docker-compose

我的docker文件

FROM tiangolo/uvicorn-gunicorn-fastapi:python3.7

COPY ./requirements.txt /requirements.txt
RUN pip install -r /requirements.txt 

COPY . /app

WORKDIR /app
ADD . /app

ENV DATABASE_URL="postgres://superuser:superuser@localhost:5433/al-test-3" 

EXPOSE 8000

CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]

和docker-compose.yml

version: '3.8'
services:
  al_test:
    build: /
    ports:
     - 5001:80
  postgresql:
    image: "bitnami/postgresql:latest"
    volumes:
      - postgresql-data:/bitnami/postgresql
    ports:
      - "5446:5432"
    environment:
      - POSTGRESQL_DATABASE=al-test-3
      - POSTGRESQL_USERNAME=superuser
      - POSTGRESQL_PASSWORD=superuser
      - POSTGRESQL_POSTGRES_PASSWORD=superuser

volumes:
  postgresql-data:

1 个答案:

答案 0 :(得分:1)

TL; DR

我认为存在问题:

    build: /

要使用本地文件夹作为上下文进行构建,您应该说

    build: ./

到底发生了什么?

话虽如此,您的项目的结构如何?您的Dockerfile在哪里?是

app
    - some.py
Dockerfile
requirement.txt
docker-compose.yaml

docker-compose.yml的角度来看,./是它所在的文件夹。在Unix文件系统中,/代表文件系统的根目录 ;您将如何称呼C:\

在构建时

我不确定 docker 如何与Windows集成在一起,但可能/被翻译为您的docker恶魔无权阅读的地方,这引起了PermissionError

在运行时

在尝试将各种文件夹装入容器时,您可能会遇到类似的正确问题。这是修复程序(发生时)