2018-11-02 13:12
浏览 769


I want to put my code inside a docker container, I have created dockerfile and when I run, I got an error

internal/server/handlers.go:16:2: cannot find package "" in any of:
    /usr/local/go/src/ (from $GOROOT)
    /go/src/ (from $GOPATH)

but when I launch my code locally without docker by typing go run main.go everything is fine

图片转代码服务由CSDN问答提供 功能建议


  internal / server / handlers.go:16:2:在以下任何位置都找不到软件包“”:
 / usr / local / go  /src/来自$ GOROOT)
 /go/src/来自$ GOPATH)

但是当我通过键入go run main.go在没有docker的情况下在本地启动代码时,一切都很好

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doujia2463 2018-11-02 14:07

    Make sure you installed all your package inside container. Because your docker container is a different machine with your current computer. You need to make sure that all dependencies package installed in your docker image. For an Dockefile example, install my package at Dockerfile as you can see:

    FROM golang:latest
    # Create working folder
    RUN mkdir /app
    COPY . /app
    RUN apt -y update && apt -y install git
    RUN go get
    RUN go get
    RUN go get
    RUN go get
    RUN go get
    WORKDIR /app 

    Now you run docker run -it -p 8080:8080 your_docker_image_name go run main.go should work.

    打赏 评论

相关推荐 更多相似问题