我正在尝试用我的 Go 二进制文件创建一个用作数据库迁移器的容器。但是,如果我运行二进制文件,虽然它能完美地工作,但是我很难把它放到容器中并在 docker-compose 堆栈中运行它。
下面是我的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"]
当我运行 docker-compose 堆栈时,MySQL 数据库得到了正确的设置,但是我在数据库迁移器容器的日志中收到了这个错误:
data-migrator_1 | standard_init_linux.go:190: exec user process caused "exec format error"