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

I'm trying to set up a Docker development environment on Windows. I have a code directory structur

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744694448a4588406.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信