douzhi3454 2019-04-25 13:04
浏览 159

Golang Dockerfile:无法在Docker构建中找到软件包,但可以正常运行

I have the following dockerfile setup for a multistage build for my golang microservice project

FROM golang:alpine as builder

RUN apk --no-cache add git

WORKDIR /app/vessel-service

COPY . .

RUN go mod download
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o vessel-service

# Second Stage

I have the following imports in my main.go

import (

  pb ""
  micro ""

where the vessel-service one is for the current project.

On running docker build -t vessel-service . I get the following error

Step 5/12 : RUN go mod download
 ---> Running in 1d0121039462
warning: pattern "all" matched no module dependencies
Removing intermediate container 1d0121039462
 ---> b66add421d26
Step 6/12 : RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o vessel-service
 ---> Running in ef50eff44a3b
main.go:9:3: cannot find package "" in any of:
  /usr/local/go/src/ (from $GOROOT)
  /go/src/ (from $GOPATH)
main.go:8:3: cannot find package "" in any of:
  /usr/local/go/src/ (from $GOROOT)
  /go/src/ (from $GOPATH)

But I do have ~/go/src/ On trying to just directly run main.go, it runs without any issues.

Is this an issue with my environment setup or is there something more to this?

Here's a summary of my go.mod


    go 1.12

    require (
      ... v1.1.0
    replace => v0.0.0-20190108154635-47c0da630f72

    replace => v0.5.1

    replace => v0.0.0-20190409202823-959b441ac422

    replace => v1.4.1
  • 写回答



      相关推荐 更多相似问题


      • ¥15 session失效问题
      • ¥15 GMS地下水数值模拟无法打开
      • ¥15 树型结构的数据怎么匹配分支
      • ¥15 stm32F4用.引不出来结构体成员怎么解决
      • ¥15 .exe文件打不开怎么解决?
      • ¥30 Syntax Error: TypeError: this.getOptions is not a function的问题
      • ¥15 eclipse Android环境搭建
      • ¥15 unity中脚本之间的继承有什么作用
      • ¥15 C语言内存对齐代码不太理解
      • ¥15 uniapp中的uni-file-picker组件多图上传,删除,显示。以及C#.Net后端处理问题