我写了一个多阶段构建 dockerfile 试图遵循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"]
我希望它在 /compiling 目录中构建一个可执行文件,将其复制到 /running 目录并在那里运行它。但是,我得到这个输出:
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
我不完全知道为什么会这样。你可以解释吗?如何修复?