dougu2240
2018-11-02 13:12
浏览 769

如何避免找不到包“ github.com/golang/protobuf/jsonpb”错误

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 "github.com/lib/pq" in any of:
    /usr/local/go/src/github.com/lib/pq (from $GOROOT)
    /go/src/github.com/lib/pq (from $GOPATH)

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

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

我想将代码放入docker容器中,我创建了dockerfile,当我运行时,出现错误

  internal / server / handlers.go:16:2:在以下任何位置都找不到软件包“ github.com/lib/pq”:
 / usr / local / go  /src/github.com/lib/pq(来自$ GOROOT)
 /go/src/github.com/lib/pq(来自$ 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 github.com/go-sql-driver/mysql
    RUN go get github.com/gosimple/slug
    RUN go get github.com/gin-gonic/gin
    RUN go get gopkg.in/russross/blackfriday.v2
    RUN go get github.com/gin-gonic/contrib/sessions
    WORKDIR /app 
    

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

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题