简体   繁体   English

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

[英]How to avoid cannot find package “github.com/golang/protobuf/jsonpb” error

I want to put my code inside a docker container, I have created dockerfile and when I run, I got an error 我想将代码放入docker容器中,创建了dockerfile,运行时出现错误

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 但是当我通过键入go在本地运行我的代码而没有docker时运行main.go一切都很好

Make sure you installed all your package inside container. 确保将所有软件包安装在容器中。 Because your docker container is a different machine with your current computer. 因为您的Docker容器与当前计算机是另一台计算机。 You need to make sure that all dependencies package installed in your docker image. 您需要确保在Docker映像中安装了所有依赖项程序包。 For an Dockefile example, install my package at Dockerfile as you can see: 对于Dockefile示例,请在Dockerfile上安装我的软件包,如下所示:

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. 现在运行docker run -it -p 8080:8080 your_docker_image_name go run main.go应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM