I'm trying to create Go web server into small Docker images. Ideally the clean image contains only the Go application itself (and maybe supporting web components, but not the Go-building environment).
Here is my
# golang:latest as build-env FROM golang:latest AS build-env RUN mkdir /app ADD . /app/ WORKDIR /app RUN cd /app && GO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o myapp . # go build -o myapp FROM scratch COPY --from=build-env /app/myapp /app/images / EXPOSE 8080 ENTRYPOINT /myapp
It uses the Docker Builder Pattern and scratch image, which is a special docker image that's empty.
It builds OK, but when I run it, I'm getting:
docker: Error response from daemon: OCI runtime create failed: container_linux.go:344: starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory": unknown.
ENTRYPOINT need to be changed to the exec form:
Having done that, I'm getting a new error:
standard_init_linux.go:207: exec user process caused "no such file or directory"
Having use a small footprint Linux image as the base (i.e. Alpine Linux) instead of scratch wouldn't help either:
$ docker run -it -p 8080:8080 go-web-docker-small standard_init_linux.go:207: exec user process caused "no such file or directory" $ docker run -it -p 8080:8080 go-web-docker-small /bin/sh -i standard_init_linux.go:207: exec user process caused "no such file or directory"
How to fix it? Thx!