我在构建 go 服务的 Docker 映像时遇到问题(请参阅最后的错误消息)。我的服务代码结构如下:
cmd
- duc-adobe
pkg
- adobe
- common
.gitignore
Dockerfile
go.mod
go.sum
这是我的 Dockerfile:
# build image
FROM golang:1.12-alpine as builder
RUN apk update && apk add --no-cache git ca-certificates && update-ca-certificates
WORKDIR /app
# first download dependencies so that we can utilize the docker cache
COPY go.mod .
COPY go.sum .
RUN go mod download
RUN CGO_ENABLED=0 go build ./cmd/duc-adobe -o /go/bin/app
# executable image
FROM alpine:3.9
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /go/bin/app /go/bin/app
ENTRYPOINT ["/go/bin/app"]
问题
构建失败,我不知道如何解决这个问题。这是输出:
Step 1/11 : FROM golang:1.12-alpine as builder
---> 6b21b4c6e7a3
Step 2/11 : RUN apk update && apk add --no-cache git ca-certificates && update-ca-certificates
---> Using cache
---> 14b9eb869a9f
Step 3/11 : WORKDIR /app
---> Using cache
---> c2d0df63dc21
Step 4/11 : COPY go.mod .
---> Using cache
---> abd95c3f18eb
Step 5/11 : COPY go.sum .
---> Using cache
---> 3d49861b4f74
Step 6/11 : RUN go mod download
---> Using cache
---> 3cc3c7752c04
Step 7/11 : RUN CGO_ENABLED=0 go build ./cmd/duc-adobe -o /go/bin/app
---> Running in b1034f9c05bb
go: directory /go/bin/app outside available modules
The command '/bin/sh -c CGO_ENABLED=0 go build ./cmd/duc-adobe -o /go/bin/app' returned a non-zero code: 1
我不确定在什么意义上我需要使 go 模块可访问或者如何解决这个问题?
开满天机
相关分类