docker - 使用 lint 命令构建 docker go 应用程序

标签 docker go dockerfile

我已经创建了以下 docker 容器,除了 make lint 之外的所有东西都可以工作

在项目根目录中,我有包含当前条目的Makefile

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

当我在我的机器 (macbook) 本地使用它时,如果例如文件未格式化 go fmt 我在执行上面的代码时出错。

问题是,当我通过 docker build 命令

创建 docker 镜像时

我遇到了与我的项目无关的不同 linting 问题。 在 gometalinter.json 中,我有以下条目来绕过 vendor 目录

{
  "vendor": true
}

这是docker内容

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

当我运行 lint 时,这是我得到的,与我的项目无关

../../../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)

最佳答案

您没有正确设置 environment variable in your Dockerfile .

运行 CGO_ENABLED=0

应该是

ENV CGO_ENABLED=0

关于docker - 使用 lint 命令构建 docker go 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53750330/

相关文章:

node.js - 在 docker 容器中安装 Mongoose

docker - 是否可以像Windows 7一样在窗口服务器中运行docker客户端?

docker - 无法在 Windows 10 中启动 Docker 容器

ruby - 在Docker容器中访问Sinatra应用程序的问题

Golang - 将 "inheritance"添加到结构中

docker - FROM命令的用途-Docker文件

dockerfile - 使用 Jenkins 将 Docker 镜像部署到 AWS ECS

json - 需要帮助使用 Go 更新 JSON 负载

docker - 从远程机器访问托管在 digital ocean 水滴上的容器化 API

Dockerfile - 如何使用 ENV 指令附加 PATH?