2018-11-26 10:53
浏览 152


I use Docker to add my project to it, now I want to run some test on it and I got errors that the test failed

Any idea what I miss here?

# build stage
FROM golang:1.11.1-alpine3.8 AS builder

RUN apk add --update --no-cache make \

ADD /usr/bin/dep
RUN chmod +x /usr/bin/dep

RUN mkdir -p $GOPATH/src/
COPY Gopkg.toml Gopkg.lock ./
RUN dep ensure --vendor-only
COPY . ./

Now I build the docker which finish successfully and now I want to run tests on it.

I did docker run docker run -it goapp which run successfully

And now I use command go test -v ./... and I got error

# runtime/cgo
exec: "gcc": executable file not found in $PATH
FAIL [build failed]
FAIL [build failed]

Any idea how to resolve this ?

I try another step in docker file like following which doesnt helps

RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix nocgo -o /go-application .
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douzong6649
    douzong6649 2018-11-26 11:06

    You've disabled CGO for your build, but you're not disabling CGO for your tests, which you must do:

    CGO_ENABLED=0 GOOS=linux go test -v ./...
    点赞 评论