dougu2240 2018-11-02 13:12
浏览 1655
已采纳

如何避免找不到包“ 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

  • 写回答

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站