docker-compose - 添加失败:构建上下文之外的禁止路径 [英] docker-compose - ADD failed: Forbidden path outside the build context
问题描述
我有这样的文件夹结构
project
- config
-docker
Dockerfile
docker-compose.yml
- src
here_is_code
requirements.txt
Dockerfile
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD ../../requirements.txt /code/
RUN pip install -r requirements.txt
ADD src /code/
docker-compose.yml
docker-compose.yml
version: '3'
services:
web:
build:
context: ../../
dockerfile: config/docker/Dockerfile
command:
bash -c "ls"
volumes:
- .:/code
expose:
- "8000"
nginx:
image: nginx
ports:
- "8000:8000"
volumes:
- .:/code
- ./config/nginx:/etc/nginx/conf.d
depends_on:
- web
当我运行 docker-compose build
时出现以下错误:
When I run docker-compose build
I get following error:
服务'web'构建失败:添加失败:构建上下文之外的禁止路径:../../requirements.txt()
Service 'web' failed to build: ADD failed: Forbidden path outside the build context: ../../requirements.txt ()
是否可以添加requirements.txt 或者我必须将此文件复制到docker 目录中?或者我可能需要使用任何入口点 (entrypoint.sh)?
Is it possible to add requirements.txt or I'll have to copy this file into docker directory? Or maybe I need to use any entrypoint (entrypoint.sh)?
更新
在 docker build -f config/docker/Dockerfile .
和 docker-compose up
之后,我在那里看不到我的代码.这是 ls -R/code
After docker build -f config/docker/Dockerfile .
and docker-compose up
I can't see my code there. Here is the output of ls -R /code
web_1 | /code:
web_1 | Dockerfile
web_1 | config
web_1 | docker-compose.yml
web_1 | src
web_1 | static
web_1 |
web_1 | /code/config:
web_1 | nginx
web_1 |
web_1 | /code/config/nginx:
web_1 |
web_1 | /code/src:
web_1 | static
web_1 |
web_1 | /code/src/static:
web_1 |
web_1 | /code/static:
推荐答案
context
一切都与上下文有关.在您的构建中指定上下文和 dockerfile,您可以在任何地方植入 Dockerfile.用它玩一轮(这是她说的).
It's all about context. Specify context and dockerfile in your build and you can plant your Dockerfile anywhere. Play a round with it (that's what she said).
我至少会将 docker-compose.yaml 保存在根目录中.
I would at least keep the docker-compose.yaml in a root directory.
build:
context: .
dockerfile: dockerfiles/project-one/Dockerfile
这篇关于docker-compose - 添加失败:构建上下文之外的禁止路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!