使用 Docker 多階段構(gòu)建部署簡(jiǎn)單 API 時(shí),會(huì)拋出以下錯(cuò)誤:$ docker build -t api:latest .[...]$ docker run -p 4880:4880 --rm --name=api api:latest2019/01/29 23:02:15 exec: "go": executable file not found in $PATH由于我的應(yīng)用程序沒(méi)有g(shù)o從任何地方(或任何地方exec.Command)調(diào)用我運(yùn)行了一個(gè)go mod vendor所以我可以檢查依賴源代碼并找到以下內(nèi)容:vendor/github.com/lib/pq/oid/gen.go12: "os/exec"64: cmd := exec.Command("gofmt")這可能是問(wèn)題所在嗎?如果是,我該如何解決?我確信我之前已經(jīng)成功地部署了github.com/lib/pq多階段構(gòu)建,但我目前被卡住了。非常感謝,Happy Hacking。文件FROM golang:1-alpine AS builderENV GO111MODULE=onRUN apk --no-cache add ca-certificates gitWORKDIR /app# Copy go module info first...COPY go.mod .COPY go.sum .# ...then download to cache dependencies between buildsRUN go mod downloadCOPY . .RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -installsuffix cgo -ldflags '-extldflags "-static"' -o api cmd/api/FROM scratchWORKDIR /appCOPY --from=builder /app/api /app/COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/EXPOSE 8080ENTRYPOINT ["./api"]
1 回答

鴻蒙傳說(shuō)
TA貢獻(xiàn)1865條經(jīng)驗(yàn) 獲得超7個(gè)贊
您的實(shí)際構(gòu)建線:
RUN?CGO_ENABLED=0?GOOS=linux?GOARCH=amd64?go?build?-installsuffix?cgo?-ldflags?'-extldflags?"-static"'?-o?api?cmd/api/
前面缺少相對(duì)路徑cmd
,將其設(shè)為 be./cmd/api
將導(dǎo)致構(gòu)建/運(yùn)行成功。cmd/api
顯然是真實(shí)的,所以它沒(méi)有犯錯(cuò),但也沒(méi)有做你期望它做的事情。如果您go run cmd/api
在終端中輸入,您應(yīng)該會(huì)看到大量與您的應(yīng)用程序無(wú)關(guān)的輸出。
- 1 回答
- 0 關(guān)注
- 212 瀏覽