admin管理员组文章数量:1391981
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 theproject/
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 filebuild
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
1 Answer
Reset to default 5COPY ../ .
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.
本文标签: javascriptHow to use multiple Dockerfiles within a monorepoStack Overflow
版权声明:本文标题:javascript - How to use multiple Dockerfiles within a monorepo? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744694448a2620192.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论