Gordienko R.
Gordienko R.

Reputation: 341

How to set correct path to copy files with multi-step docker build?

Here is Dockerfile:

# tag block to refering
FROM node:alpine as builder
WORKDIR /home/server
COPY package.json .
RUN npm install
COPY . .
CMD ["npm", "run", "build"]

# on second step use another core image
FROM nginx

# copy files builded on previous step
COPY --from=builder /home/server/build usr/share/nginx/html

When image is builded on local machine with command 'docker build .' - it works fine, but when I trying to put the project to zeit I get next error:

Step 8/8 : COPY --from=builder /home/server/build usr/share/nginx/html
> COPY failed: stat   /var/lib/docker/overlay2/a114ae6aae803ceb3e3cffe48fa1694d84d96a08e8b84c4974de299d5fa35543/merged/home/server/build: no such file or directory

What it can be? Thanks.

Upvotes: 0

Views: 917

Answers (1)

David Maze
David Maze

Reputation: 159156

Your first stage doesn't actually RUN the build command, so the build directory is empty. Change the CMD line to a RUN line.

One tip: each separate line of the docker build sequence produces its own intermediate layer, and each layer is a runnable Docker image. You'll see output like

Step 6/8: CMD ["npm", "run", "build"]
 ---> Running in 02071fceb21b
 ---> f52f38b7823e

That last number is a valid Docker image ID and you can

docker run --rm -it f52f38b7823e sh

to see what's in that image.

Upvotes: 1

Related Questions