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

如何避免找不到包“ 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 Python语言实验
  • ¥15 SAP HANA SQL 增加合计行
  • ¥20 用C#语言解决一个英文打字练习器,有偿
  • ¥15 srs-sip外部服务 webrtc支持H265格式
  • ¥15 在使用abaqus软件中,继承到assembly里的surfaces怎么使用python批量调动
  • ¥15 大一C语言期末考试,求帮助🙏🙏
  • ¥15 ch340驱动未分配COM
  • ¥15 Converting circular structure to JSON
  • ¥30 Hyper-v虚拟机相关问题,求解答。
  • ¥15 TSM320F2808PZA芯片 Bootloader