访问Dockerfile中的上下文外部 [英] Access to outside of context in Dockerfile

查看:182
本文介绍了访问Dockerfile中的上下文外部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Maven项目中,我具有以下结构:

In my Maven project I have following structure:

docker/
   docker-compose.yml
   A/
     Dockerfile
   B/
     Dockerfile
src/
target/
   foo.war

在A的Dockerfile中,我需要使用以下命令访问 / target 文件夹中的war:

In A's Dockerfile I need access to war in /target folder with the following command:

COPY ../../target/foo.war /usr/local/tomcat/webapps/foo.war

当我运行 docker-compose up tt时出现错误

when I run docker-compose up tt gives me error


生成失败:COPY失败:生成
上下文之外的禁止路径:../../ target / foo.war

failed to build: COPY failed: Forbidden path outside the build context: ../../target/foo.war

docker-compose.yml

docker-compose.yml

version: '3.6'
services:
  fooA:
    build: ./docker/A
    ports:
      - "8080:8080"
    depends_on:
      - fooB

  fooB:
    build: ./docker/fooB
    ports:
      - "5433:5433"

您能告诉我如何解决吗?我不想在每个项目构建后手动复制war文件。

Can you tell me how to solve this? I don't want copy war file manually after every project build.

推荐答案

据我所知,无法访问东西在构建上下文之外。

As far as I know it's not possible to access things outside out your build context.

dockerfile 指令与 context 指令如下:

build:
  context: .
  dockerfile: A/Dockerfile

您可能希望包含 .dockerignore 在项目根目录中,以防止将整个项目发送到docker守护进程,从而可能导致构建速度变慢。

You may wish to include a .dockerignore in the project root dir to prevent the entire project being send to the docker daemon resulting in potentially much slower builds.

这篇关于访问Dockerfile中的上下文外部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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