最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to use multiple Dockerfiles within a monorepo? - Stack Overflow

programmeradmin2浏览0评论

I'm trying to set up a Docker development environment on Windows. I have a code directory structure like so:

project/
  node-app/
  react-app-1/
  react-app-2/
  shared/

node-app, react-app-1 and react-app-2 all depend upon the code within shared. So, I was thinking of having a Dockerfile in each of the apps, with something like this:

FROM node:10.0

WORKDIR /app
COPY ../ .

WORKDIR /app/node-app
RUN npm install

However, that doesn't work - Docker gives me an error saying that it's a Forbidden path outside the build context: ../.

What is the best way to resolve this problem? I'm looking at setting up some sort of Docker Compose after I get this sorted (once again for local development), so my ideal solution would keep that in mind.

I'm trying to set up a Docker development environment on Windows. I have a code directory structure like so:

project/
  node-app/
  react-app-1/
  react-app-2/
  shared/

node-app, react-app-1 and react-app-2 all depend upon the code within shared. So, I was thinking of having a Dockerfile in each of the apps, with something like this:

FROM node:10.0

WORKDIR /app
COPY ../ .

WORKDIR /app/node-app
RUN npm install

However, that doesn't work - Docker gives me an error saying that it's a Forbidden path outside the build context: ../.

What is the best way to resolve this problem? I'm looking at setting up some sort of Docker Compose after I get this sorted (once again for local development), so my ideal solution would keep that in mind.

Share Improve this question edited Mar 23, 2019 at 12:41 jonrsharpe 122k30 gold badges268 silver badges476 bronze badges asked Mar 23, 2019 at 12:34 ZeriumZerium 17.4k32 gold badges118 silver badges187 bronze badges 2
  • docs.docker./engine/reference/builder explains how the context works. If you docker build . from the project/ directory you can get the right context, and you have to specify which Dockerfile to select with -f/--file. You can also set explicit context and file in the pose file build section: docs.docker./pose/pose-file/#build – jonrsharpe Commented Mar 23, 2019 at 12:40
  • 1 Possible duplicate of How to include files outside of Docker's build context? – jonrsharpe Commented Mar 23, 2019 at 12:42
Add a ment  | 

1 Answer 1

Reset to default 5

COPY ../ . is invalid because .. is outside the build context (by default this is the directory from where the docker build mand is issued).

To fix that, you could build your application from the top directory ($PWD = project/), thus making all files/directories in that directory available from the build context, and specify the Dockerfile you want to use for the build :

cd project/ && docker build -t <your_image_name> -f node-app/Dockerfile .

or :

docker build -t <your_image_name> -f /path/to/project/node-app/Dockerfile /path/to/project/

And of course replace COPY ../ . by COPY . ., since you are now building from the top directory.

发布评论

评论列表(0)

  1. 暂无评论