我正在尝试使用 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 …
Run Code Online (Sandbox Code Playgroud)