dtxpz8785 2019-03-12 07:06
浏览 183

在Docker容器中使用Go模块时找不到包错误

Given I have some experience working with docker containers I decided to use docker containers to have a go environment and learn. Below is my dockerfile for go web app.

FROM golang:1.12.0-alpine3.9 as base

ARG GO111MODULE=on

RUN apk update && apk add make bash git

COPY ./app /go/src/app
WORKDIR /go/src/app
RUN go build

COPY ./compose/local/golang/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

RUN go get github.com/oxequa/realize

ENTRYPOINT [ "/entrypoint.sh" ]
CMD ["realize", "start"]

My go.mod file

module github.com/rajeshyogeshwar/demoapp

go 1.12

require (
    github.com/Sirupsen/logrus v1.0.6
    github.com/joho/godotenv v1.3.0
    github.com/julienschmidt/httprouter v1.2.0
    github.com/lib/pq v1.0.0
    github.com/spf13/cobra v0.0.3
    github.com/spf13/viper v1.2.0
)

and finally my project folder structure

enter image description here

As we can see I am trying to use httprouter module and it has been defined in my go.mod file. But I keep getting following error.

app_1        | [06:46:56][APP] : Install 
app_1        |  main.go:8:2: cannot find package "github.com/julienschmidt/httprouter" in any of:
app_1        |  /usr/local/go/src/github.com/julienschmidt/httprouter (from $GOROOT)
app_1        |  /go/src/github.com/julienschmidt/httprouter (from $GOPATH)

So if anyone can point out the obvious mistake it would be great.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程
    • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
    • ¥15 关于smbclient 库的使用
    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害