0

i’ve the following docker file which works OK, I use multistage build and the “runner” uses 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 ./

Now I want to change the runner stage to use scratch image and try like following:


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”]

The error is

curl: (23) Failed writing body (0 != 1132)

what I need is to copy also (not just bin) the certificate from the first stage to the second stage with scratch image

Jenny M
  • 923
  • 1
  • 14
  • 37
  • @JohnKugelman - sorry, I dont want to use the `apk` commands as I dont need them, I just want to copy the certifcate to the scratch image in the second stage , is it possilbe ? – Jenny M Jun 04 '19 at 16:30
  • @thiagobraga - try it without success, any other idea ? – Jenny M Jun 04 '19 at 16:40
  • Is this URL valid? http://aia.pki.vs.com/aia/0CA.crt Because there is nothing wrong with your Dockerfile. I've tested your multi-stage build in Play with Docker and it runs successfully, but I needed to comment the `curl` line. https://labs.play-with-docker.com – thiagobraga Jun 04 '19 at 17:44

0 Answers0