docker-compose-添加失败:构建上下文之外的禁止路径 [英] docker-compose - ADD failed: Forbidden path outside the build context

查看:516
本文介绍了docker-compose-添加失败:构建上下文之外的禁止路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的文件夹结构

project
    - config
        -docker
           Dockerfile
           docker-compose.yml
    - src
       here_is_code
    requirements.txt

Dockerfile

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:


推荐答案

上下文

所有与上下文有关。在构建中指定上下文和dockerfile,然后就可以将Dockerfile植入任何地方。

It's all about context. Specify context and dockerfile in your build and you can plant your Dockerfile anywhere.

我至少将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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆