I am attempting to create a container with my Go binary in for use as a database migrator. If I run the binary it works perfectly, however, I am struggling to put it into a container and run it in my docker-compose stack.
Below is my Dockerfile.
FROM golang:1.11 AS build_base
WORKDIR /app
ENV GO111MODULE=on
# We want to populate the module cache based on the go.{mod,sum} files.
COPY go.mod .
COPY go.sum .
RUN go mod download
FROM build_base AS binary_builder
# Here we copy the rest of the source code
COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build
#In this last stage, we start from a fresh Alpine image, to reduce the image size and not ship the Go compiler in our production artifacts.
FROM alpine AS database-migrator
# We add the certificates to be able to verify remote instances
RUN apk add ca-certificates
COPY --from=binary_builder /app /app
ENTRYPOINT ["/app/binary-name"]
When I run my docker-compose stack the MySQL database gets setup correctly but I receive this error in the logs for my database migrator container.
data-migrator_1 | standard_init_linux.go:190: exec user process caused "exec format error"