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.
COPY ../ . is invalid because .. is outside the build context (by default this is the directory from where the docker build command 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With