我遇到了一個奇怪的問題來運行Go Echo框架。當(dāng)我使用該命令時,它工作正常,這不是依賴問題,它正確執(zhí)行文件,但在運行時它給出錯誤:docker rundocker-compose upCreating echo_app ... doneAttaching to echo_appecho_app | server.go:6:2: cannot find package "github.com/labstack/echo/v4" in any of:echo_app | /usr/local/go/src/github.com/labstack/echo/v4 (from $GOROOT)echo_app | /go/src/github.com/labstack/echo/v4 (from $GOPATH)echo_app exited with code 1以下是我的文件:DockerfileFROM golang:1.15-alpineLABEL maintainer="Me"RUN apk updateRUN apk add git# Setting up Dev environmentRUN mkdir /echo_appCOPY . /echo_app/WORKDIR /echo_app/# Download Echo Framework with help of Go mod (Credit: https://github.com/labstack/echo/issues/1374#issuecomment-559990790)# Init to create Go ModuleRUN go mod init app.com/main# Building to download echo framework and other dependenciesRUN go build# RUN the server#CMD go run server.go EXPOSE 1323docker-compose.ymlversion: "3"services: web: container_name: echo_app image: echo_app:latest build: ./ command: go run server.go volumes: - .:/echo_app ports: - "1323:1323"
1 回答

富國滬深
TA貢獻1790條經(jīng)驗 獲得超9個贊
FROM golang:1.15-alpine
LABEL maintainer="Me"
# Setting up Dev environment
WORKDIR /echo_app/
# note this file, go.mod exists locally. and contain reference
# to direct/indirect dependencies. this step allows to download
# dependencies and speedup build for docker images (if it used
# to build artifacts, and not as dev env).
COPY go.mod /echo_app/go.mod
RUN go mod download
EXPOSE 1323
- 1 回答
- 0 關(guān)注
- 88 瀏覽
添加回答
舉報
0/150
提交
取消