我有以下工作正常的 docker 文件,我使用多阶段构建和“跑步者”使用 FROM golang:1.11.4-alpine3.8
FROM golang:1.11.4-alpine3.8 AS builder
ENV SOURCES /github/myapp
RUN apk add --update --no-cache make curl \
git
ADD https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 /usr/bin/dep
RUN chmod +x /usr/bin/dep
WORKDIR $GOPATH/src/${SOURCES}
COPY Gopkg.toml Gopkg.lock ./
RUN dep ensure
# Copy project
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix nocgo -o bin .
# Runner
FROM golang:1.11.4-alpine3.8
RUN apk add --update --no-cache curl \
# Install CA cert
RUN curl -sSL -f -k http://aia.pki.vs.com/aia/0CA.crt -o /usr/share/pki/trust/anchors/CA.crt && \
update-ca-certificates
COPY --from=builder /bin ./
现在我想更改跑步者阶段以使用临时图像并尝试如下:
FROM golang:1.11.4-alpine3.8 AS builder
ENV SOURCES /github/myapp
RUN apk add --update --no-cache make curl \
git
ADD https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 /usr/bin/dep
RUN chmod +x /usr/bin/dep
# Install CA cert
RUN curl -sSL -f -k http://aia.pki.vs.com/aia/0CA.crt -o /usr/share/pki/trust/anchors/CA.crt && \
update-ca-certificates
WORKDIR $GOPATH/src/${SOURCES}
COPY Gopkg.toml Gopkg.lock ./
RUN dep ensure
# Copy project
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix nocgo -o bin .
# THIS IS THE CHANGE
FROM scratch
COPY --from=builder /bin ./
COPY --from=builder /usr/share/pki/trust/anchors/CA.crt /usr/share/pki/trust/anchors/CA.crt
ENTRYPOINT [“./bin”]
错误是
curl: (23) Failed writing body (0 != 1132)
我需要的是将证书从第一阶段复制到第二阶段(不仅仅是bin),并带有临时图像