multi stage docker build with nginx image

Viewed 405

I'm trying to build an nginx image for a react project app.

Here is my Dockerfile:

FROM node:14-alpine as myapp
EXPOSE 3000
WORKDIR = /snakeapp
COPY package.json .
RUN yarn install --network-timeout 1000000
COPY . .
RUN yarn build

FROM nginx
COPY --from=myapp /snakeapp/build /usr/share/nginx/html
EXPOSE 8080
CMD ["nginx", "-g", "daemon off;"]

The error I'm getting during the build image is:

...
Status: Downloaded newer image for nginx:latest
 ---> 08b152afcfae
Step 9/11 : COPY --from=myapp /snakeapp/build /usr/share/nginx/html
COPY failed: stat snakeapp/build: file does not exist

Could you please give me a hint which directory isn't existing.

If I create only the first image, the ls /snakeapp shows me the following content, as we can see the build file exist.

/= /snakeapp # ls
build              package-lock.json  src                yarn.lock
node_modules       package.json       webpack.config.js
1 Answers

Did you notice the weird folder name /= /snakeapp? That's because of WORKDIR = .... Remove that =.

WORKDIR /snakeapp
Related