我正在尝试multi-stage builds,并从以下Dockerfile开始:
FROM golang:latest AS build
ENV GO111MODULE on
ENV GOOS linux
WORKDIR /build
ADD main.go .
RUN go mod init caddy
RUN go build
FROM alpine:latest
WORKDIR /app
COPY --from=build /build/caddy ./caddy
CMD "./caddy"
构建日志看起来不错:
Step 1/11 : FROM golang:latest AS build
---> a1072a078890
Step 2/11 : ENV GO111MODULE on
---> Running in 15d89fe6e4f4
Removing intermediate container 15d89fe6e4f4
---> d65cead90351
Step 3/11 : ENV GOOS linux
---> Running in 9ee1c730bd2e
Removing intermediate container 9ee1c730bd2e
---> 98cbf8d9ff94
Step 4/11 : WORKDIR /build
---> Running in 8cf4b491df08
Removing intermediate container 8cf4b491df08
---> cabdb71ef8f2
Step 5/11 : ADD main.go .
---> d6e01c42a24c
Step 6/11 : RUN go mod init caddy
---> Running in 9718a450ccb7
go: creating new go.mod: module caddy
Removing intermediate container 9718a450ccb7
---> 290f25973b0a
Step 7/11 : RUN go build
---> Running in 8f65e4d02d1c
go: finding github.com/pyed/ipfilter v1.1.4
go: finding github.com/aablinov/caddy-geoip latest
(... successful "finding", "downloading" steps ...)
go: finding gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7
go: finding gopkg.in/fsnotify.v1 v1.4.7
Removing intermediate container 8f65e4d02d1c
---> eb63824b8795
Step 8/11 : FROM alpine:latest
latest: Pulling from library/alpine
63bc94deeb28: Pull complete
Digest: sha256:7c92a2c6bbcb6b6beff92d0a940779769c2477b807c202954c537e2e0deb9bed
Status: Downloaded newer image for alpine:latest
---> c85b8f829d1f
Step 9/11 : WORKDIR /app
---> Running in 1099076a5e16
Removing intermediate container 1099076a5e16
---> 419bb0ef875e
Step 10/11 : COPY --from=build /build/caddy ./caddy
---> 49213be447ce
Step 11/11 : CMD "./caddy"
---> Running in 6a91d4783d8b
Removing intermediate container 6a91d4783d8b
---> 940b1494793b
Successfully built 940b1494793b
Successfully tagged caddy-docker-proxy:latest
Creating container...
Container Id: eeda1a1bd57e19180b664376546b3128ed28c9ff37317c013829faae4a859978
Container name: 'caddy-docker-proxy'
Attaching to container 'caddy-docker-proxy'...
Starting container 'caddy-docker-proxy'
由于
,图像无法开始/bin/sh: ./caddy: not found
我认为这是一步
Step 10/11 : COPY --from=build /build/caddy ./caddy
---> 49213be447ce
表示复制成功。否则,可能会出现有关找不到要复制的工件的错误(我想)
我尝试了COPY --from=build /build/caddy ./caddy
和/或通过CMD "/app/caddy"
开始,但是错误是相同的。
caddy
在第一个版本中在哪里?