0

I have written a multistage build dockerfile trying to follow https://docs.docker.com/engine/userguide/eng-image/multistage-build/ :

FROM gcc:latest as compiler 
WORKDIR /compiling/
ADD hello.c .
RUN gcc ./hello.c -o .hello 

FROM scratch
WORKDIR /running/
COPY --from=compiler /compiling/hello .
CMD ["./hello"]

I expect that it builds an executable in a /compiling directory, copies it to /running directory and runs it there. However, I get this output:

C:\hellonode3>docker build -t hello-node3:v6 .
Sending build context to Docker daemon  4.608kB
Step 1/8 : FROM gcc:latest as compiler
 ---> 81ffb25b1dec
Step 2/8 : WORKDIR /compiling/
 ---> Using cache
 ---> 2337f71a826d
Step 3/8 : ADD hello.c .
 ---> Using cache
 ---> aaef6bd8d2ff
Step 4/8 : RUN gcc ./hello.c -o .hello
 ---> Using cache
 ---> 665f96147ec3
Step 5/8 : FROM scratch
 --->
Step 6/8 : WORKDIR /running/
 ---> Using cache
 ---> 84f8d58a56a1
Step 7/8 : COPY --from=compiler /compiling/hello .
COPY failed: stat /var/lib/docker/overlay2/4fd98195ec5ffdb392e2d5d64c8f9acdde56c1c1e517cd9076ee9fd59ab2c4dc/merged/compiling/hello: no such file or directory

I do not exactly know why this happens. Can you explain? How can it be fixed?

user1608790
  • 393
  • 1
  • 3
  • 12

1 Answers1

-1

Just a stupid typo!

There should be a line

RUN gcc ./hello.c -o ./hello

instead.

user1608790
  • 393
  • 1
  • 3
  • 12