duanpo7282 2018-08-30 14:45
浏览 197

查找golang dockerfile的路径时出错

im trying to build docker image with my golang project

I use the following

#build stage
FROM golang:alpine as builder
WORKDIR /go/src/app
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-extldflags "-static"' -o main .
RUN apk add --no-cache git


#final stage
FROM alpine:latest
RUN apk --no-cache add ca-certificates
COPY --from=builder /go/bin/app /app
ENTRYPOINT ./app
LABEL Name=fzr-dbc  Version=0.0.1
EXPOSE 3000

This build is failing in my main.go file which is looks like following

package main

import (
    "fzr-dbc/cmd/tsr”
)

func main() {
    tsr.Execute()
}

when I run the command docker build -t fzr . The error is:

main.go:4:2: cannot find package "fzr-dbc/cmd/tsr” in any of:
        /go/src/app/vendor/fzr-dbc/cmd/tsr (vendor tree)
        /usr/local/go/src/fzr-dbc/cmd/tsr (from $GOROOT)
        /go/src/fzr-dbc/cmd/tsrs (from $GOPATH)

The error since it’s not finding my project path , what could be missing here ?

The docker file is in my root project fzr and I run the docker build from there

  • 写回答

1条回答 默认 最新

  • douhan5853 2018-08-30 15:57
    关注

    You are running go build in your Dockerfile:

    RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-extldflags "-static"' -o main .
    

    This requires you to install all your dependencies for building it.

    To fix this, either:

    1. Build the binary on your host and COPY the binary directly into the docker; or,
    2. Install dependencies inside your docker as part of RUN processes:
      • For Go before 1.11, you need to move your project source code into proper directory in GOPATH. Then, on that folder, run go get -u ./...
      • For Go 1.11+, you need to use Go 1.11 with go.mod and go.sum properly defined. Then you can use the command go mod download to download all the dependencies to the Go package cache inside your docker image.
    评论

报告相同问题?

悬赏问题

  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上