I am attempting to create a distroless docker image to put my golang binary on but whenever I run it (system is running PopOS 22.04) I get the following error:
2023/11/25 16:58:50 stat VERSION: no such file or directory
I have changed the final layer to an alpine image so I can shell into it and ensure that the binary is being copied over and can even execute it, however it does not run run with the given ENTRYPOINT
. Can someone please help me figure out what is going on? Thanks!
Build:
docker build -t mkm29/gocloak:0.2.2-alpha.7 -f Dockerfile .
Run:
docker run --rm mkm29/gocloak:0.2.2-alpha.7 help
When I only use the build image (and set the ENTRYPOINT
) I do get my help output:
docker run --rm smigula/gocloak:0.2.2-alpha.8 help
gocloak
2023/11/25 21:41:27 Debugging enabled
2023/11/25 21:41:27 Checking variables
Usage:
gocloak [flags]
gocloak [command]
Available Commands:
completion Generate the autocompletion script for the specified shell
exportRealm Export a realm from Keycloak
help Help about any command
version Print the version number of gocloak
...
Here is my Dockerfile
:
# Build the binary
ARG BASE_REGISTRY=<NEXUS_URL>
ARG TARGETOS=linux
ARG TARGETARCH=amd64
ARG GIT_COMMIT
ARG GO_VERSION
ARG VERSION
ARG BUILD_DATE
ARG BUILD_PLATFORM="${TARGETOS}/${TARGETARCH}"
ARG MAINTAINER
FROM ${BASE_REGISTRY}/ironbank/google/golang/golang-1.20:1.20.0 as builder
LABEL git-revision=${GIT_COMMIT} \
version=${VERSION} \
build-date=${BUILD_DATE} \
build-platform=${BUILD_PLATFORM} \
maintainer=${MAINTAINER} \
go-version=${GO_VERSION}
WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
# COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download
# Copy the go source
COPY . .
# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH:-amd64} go build -a -o gocloak main.go
#ENV PATH=$PATH:/workspace
#ENTRYPOINT ["/workspace/gocloak"]
# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
# FROM ${BASE_REGISTRY}/ironbank/google/distroless/base:nonroot
FROM gcr.io/distroless/static-debian12:nonroot AS final-image
ARG GIT_COMMIT
ARG GO_VERSION
ARG VERSION
ARG BUILD_DATE
ARG BUILD_PLATFORM
ARG MAINTAINER
LABEL git-revision=${GIT_COMMIT} \
version=${VERSION} \
build-date=${BUILD_DATE} \
build-platform=${BUILD_PLATFORM} \
maintainer=${MAINTAINER} \
go-version=${GO_VERSION}
COPY --chown=65532:65532 --from=builder /workspace/gocloak .
USER 65532:65532
ENTRYPOINT ["/gocloak"]