dongwu4834 2018-12-12 19:46
浏览 123
已采纳

使用lint命令构建docker go应用

I've created the following docker container , all works except on thing which is the make lint

In the project root I've Makefile with the current entry

lint:
    gometalinter --config=gometalinter.json ./...

when I use it locally in my machine (macbook) and if for example file is not formatted go fmt I get error when executing above code.

The problem is that when I create the docker image via docker build command

I got different linting issues which is not related to my project. in the gometalinter.json I've the following entry to bypass the vendor directory

{
  "vendor": true
}

This is the docker content

FROM golang:1.11.1-alpine3.7 

RUN apk add --update --no-cache git make curl bash

ADD https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 /usr/bin/dep
RUN chmod +x /usr/bin/dep

WORKDIR /go/src/my-proj

COPY . ./

COPY Gopkg.toml Gopkg.lock ./

RUN dep ensure 
# From the error it seems that this is related to cgo but even adding the next line doesnt helps, same error occurred 
RUN CGO_ENABLED=0
# this command download gometalinter which is running OK
RUN make download 

RUN make lint

when I run the lint this is what I got which is not related to my project

../../../usr/local/go/src/net/lookup_unix.go:80:24:warning: error return value not checked (undeclared name: cgoLookupHost) (errcheck)
../../../usr/local/go/src/net/lookup_unix.go:95:24:warning: error return value not checked (undeclared name: cgoLookupIP) (errcheck)
../../../usr/local/go/src/net/lookup_unix.go:107:23:warning: error return value not checked (undeclared name: cgoLookupPort) (errcheck)
../../../usr/local/go/src/net/lookup_unix.go:123:24:warning: error return value not checked (undeclared name: cgoLookupCNAME) (errcheck)
../../../usr/local/go/src/net/lookup_unix.go:323:23:warning: error return value not checked (undeclared name: cgoLookupPTR) (errcheck)
  • 写回答

1条回答 默认 最新

  • douyou8266 2018-12-12 23:36
    关注

    You are not correctly setting the environment variable in your Dockerfile.

    RUN CGO_ENABLED=0

    should be

    ENV CGO_ENABLED=0

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 Arcgis相交分析无法绘制一个或多个图形