Docker `file does not exist` 多阶段构建 COPY 命令时出错
Docker `file does not exist` Error on multi stage build COPY command
构建以下 Dockerfile 时,我收到错误“复制失败:统计调度程序:文件不存在”,但我不确定我做错了什么。
FROM golang
COPY ["dispatcher.go", "dispatcher.go"]
RUN go build dispatcher.go
FROM scratch
COPY --from=0 dispatcher .
复制 dispatcher
文件时应使用显式路径。
请注意,图像 golang
将 /go
作为工作目录。
FROM golang
COPY ["dispatcher.go", "dispatcher.go"]
RUN go build dispatcher.go
FROM scratch
COPY --from=0 /go/dispatcher /usr/local/bin/dispatcher
输出(podman
但 docker
应该以相同的方式工作):
$ docker build .
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
[1/2] STEP 1/3: FROM golang
[1/2] STEP 2/3: COPY ["dispatcher.go", "dispatcher.go"]
--> Using cache 0ea9f7534e15e49bf768e986c69bcde27001d26d674d6681ceed3096438b2d35
--> 0ea9f7534e1
[1/2] STEP 3/3: RUN go build dispatcher.go
--> Using cache 357be3e894ec59a274ef5dc7dda237743e4ab1d389ff4d247288b31987be0ae6
--> 357be3e894e
[2/2] STEP 1/2: FROM scratch
[2/2] STEP 2/2: COPY --from=0 /go/dispatcher /usr/local/bin/dispatcher
[2/2] COMMIT
--> 942793c6573
942793c6573dbe63136d329f60ccecd1eea45b40ab61703ec363e6291cc2e9f4
构建以下 Dockerfile 时,我收到错误“复制失败:统计调度程序:文件不存在”,但我不确定我做错了什么。
FROM golang
COPY ["dispatcher.go", "dispatcher.go"]
RUN go build dispatcher.go
FROM scratch
COPY --from=0 dispatcher .
复制 dispatcher
文件时应使用显式路径。
请注意,图像 golang
将 /go
作为工作目录。
FROM golang
COPY ["dispatcher.go", "dispatcher.go"]
RUN go build dispatcher.go
FROM scratch
COPY --from=0 /go/dispatcher /usr/local/bin/dispatcher
输出(podman
但 docker
应该以相同的方式工作):
$ docker build .
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
[1/2] STEP 1/3: FROM golang
[1/2] STEP 2/3: COPY ["dispatcher.go", "dispatcher.go"]
--> Using cache 0ea9f7534e15e49bf768e986c69bcde27001d26d674d6681ceed3096438b2d35
--> 0ea9f7534e1
[1/2] STEP 3/3: RUN go build dispatcher.go
--> Using cache 357be3e894ec59a274ef5dc7dda237743e4ab1d389ff4d247288b31987be0ae6
--> 357be3e894e
[2/2] STEP 1/2: FROM scratch
[2/2] STEP 2/2: COPY --from=0 /go/dispatcher /usr/local/bin/dispatcher
[2/2] COMMIT
--> 942793c6573
942793c6573dbe63136d329f60ccecd1eea45b40ab61703ec363e6291cc2e9f4