我在构建 go 服务的 Docker 映像时遇到问题(请参阅最后的错误消息)。我的服务代码结构如下:cmd - duc-adobepkg - adobe - common.gitignoreDockerfilego.modgo.sum这是我的 Dockerfile:# build imageFROM golang:1.12-alpine as builderRUN apk update && apk add --no-cache git ca-certificates && update-ca-certificatesWORKDIR /app# first download dependencies so that we can utilize the docker cacheCOPY go.mod .COPY go.sum .RUN go mod downloadRUN CGO_ENABLED=0 go build ./cmd/duc-adobe -o /go/bin/app# executable imageFROM alpine:3.9COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/COPY --from=builder /go/bin/app /go/bin/appENTRYPOINT ["/go/bin/app"]问题构建失败,我不知道如何解决这个问题。这是输出:Step 1/11 : FROM golang:1.12-alpine as builder ---> 6b21b4c6e7a3Step 2/11 : RUN apk update && apk add --no-cache git ca-certificates && update-ca-certificates ---> Using cache ---> 14b9eb869a9fStep 3/11 : WORKDIR /app ---> Using cache ---> c2d0df63dc21Step 4/11 : COPY go.mod . ---> Using cache ---> abd95c3f18ebStep 5/11 : COPY go.sum . ---> Using cache ---> 3d49861b4f74Step 6/11 : RUN go mod download ---> Using cache ---> 3cc3c7752c04Step 7/11 : RUN CGO_ENABLED=0 go build ./cmd/duc-adobe -o /go/bin/app ---> Running in b1034f9c05bbgo: directory /go/bin/app outside available modulesThe command '/bin/sh -c CGO_ENABLED=0 go build ./cmd/duc-adobe -o /go/bin/app' returned a non-zero code: 1我不确定在什么意义上我需要使 go 模块可访问或者如何解决这个问题?
1 回答
开满天机
TA贡献1786条经验 获得超12个赞
查看 go build 用法:
shubuntu1@shubuntu1:~$ go help build usage: go build [-o output] [-i] [build flags] [packages]
所以,你应该把-o
命令放在中间,比如:
go build -o /go/bin/app ./cmd/duc-adobe
- 1 回答
- 0 关注
- 99 浏览
添加回答
举报
0/150
提交
取消