【发布时间】:2019-04-21 21:26:40
【问题描述】:
我正在尝试使用我的 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 数据库设置正确,但我在数据库迁移器容器的日志中收到此错误。
数据迁移器_1 | standard_init_linux.go:190: exec 用户进程导致“exec 格式错误”
【问题讨论】:
-
链接到
golang:1.11中可用的任何共享库,而不是alpine中的任何共享库,你对这个 Dockerfile 的日子不好过。如果您想排除这种情况,ldd(在 alpine 图像中运行)是您的朋友。 -
@poc 我的回答中缺少什么?
-
问题是我在构建错误的架构!感谢您的帖子,谢谢。