-1

I'm following the guide at https://docs.docker.com/language/golang/build-images/ to learn the best way to do a multistage Docker build for a Go application. I cloned the repo:

git clone https://github.com/olliefr/docker-gs-ping

And I ran the command near the bottom of the guide to build the image:

docker build -t docker-gs-ping:multistage -f Dockerfile.multistage .

I also ran my own command to run a temporary container from the image:

docker run --rm docker-gs-ping:multistage

This worked fine. I see the application's output in my terminal. However, I wanted to switch the second layer image from the Distroless image in the guide (gcr.io/distroless/base-debian10) to alpine:3. When I made that change, built a new image, and tried to run the new image using the same command from above, I got an error about the user not existing:

docker: Error response from daemon: unable to find user nonroot: no matching entries in passwd file.

That made sense to me. It sounds like the Distroless image has that user and the Alpine image doesn't. So I removed USER nonroot:nonroot from the Dockerfile. So at this point, the second half of my Dockerfile looks like this:

##
## Deploy
##

FROM alpine:3

WORKDIR /

COPY --from=build /docker-gs-ping /docker-gs-ping

EXPOSE 8080

ENTRYPOINT ["/docker-gs-ping"]

Then I built a new image and tried to run the new image using the same command from above. This time, I got the following error:

standard_init_linux.go:228: exec user process caused: no such file or directory

I'm having trouble troubleshooting this error. Why does switching my base image this way cause this error?

Matt Welke
  • 1,441
  • 1
  • 15
  • 40

1 Answers1

1

My base images aren't in sync. The base image used in the stage used to build the binary needs to be Alpine too. If I switch the first line of that Dockerfile in the guide from FROM golang:1.16 AS build to FROM golang:1.16-alpine AS build, it works.

Matt Welke
  • 1,441
  • 1
  • 15
  • 40