亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Docker 看不到 main.go

Docker 看不到 main.go

Go
三國紛爭 2022-07-04 10:06:35
我對 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"]


查看完整回答
反對 回復 2022-07-04
  • 1 回答
  • 0 關注
  • 144 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號