我对 Docker 有一些问题。我的 dockerfile 没有看到 main.go。我有那个结构项目docker-compose.yml go.modfrontend-microservice -cmd -app -main.go -internal -some folders当我尝试启动 docker-compose 时,它给了我那个错误。ERROR: Service 'frontend-microservice' failed to build: The command '/bin/sh -c CGO_ENABLED=0 GOOS=linux go build -a -installsuffix nocgo -o /frontend-microservice .' returned a non-zero code: 1顺便说一句 dockerfile 给出与 go.mod 相关的错误我的 docker-composeversion: "3"services: frontend-microservice: build: context: ./frontend-microservice/ dockerfile: Dockerfile ports: - 80:80我的 dockerfile# golang image where workspace (GOPATH) configured at /go.FROM golang:alpine as builderADD . /go/src/frontend-microserviceWORKDIR /go/src/frontend-microserviceRUN go mod downloadCOPY . ./RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix nocgo -o /frontend-microservice .FROM alpine:latestRUN apk --no-cache add ca-certificates COPY --from=builder /frontend-microservice ./frontend-microserviceRUN mkdir ./configs COPY ./configs/config.json ./configs EXPOSE 8080 ENTRYPOINT ["./frontend-microservice"]预先感谢您的任何帮助
1 回答
慕标5832272
TA贡献1966条经验 获得超4个赞
定义函数的文件main()位于cmd/app. 不是将当前工作目录更改为cmd/app,而是附加cmd/app/main.go到go build命令。
你Dockerfile看起来像这样:
# golang image where workspace (GOPATH) configured at /go.
FROM golang:alpine as builder
ADD . /go/src/frontend-microservice
WORKDIR /go/src/frontend-microservice
RUN go mod download
COPY . ./
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix nocgo -o /frontend-microservice cmd/app/main.go
FROM alpine:latest
RUN apk --no-cache add ca-certificates
COPY --from=builder /frontend-microservice ./frontend-microservice
RUN mkdir ./configs
COPY ./configs/config.json ./configs
EXPOSE 8080
ENTRYPOINT ["./frontend-microservice"]
- 1 回答
- 0 关注
- 126 浏览
添加回答
举报
0/150
提交
取消