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.

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

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分