skip to Main Content

I have this simple Dockerfile:

FROM golang:1.16.6-buster
RUN wget -O - -q https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.45.2
RUN golangci-lint --version

When I build it, no matter how I change the second line above, I am always getting:

 > [3/3] RUN golangci-lint --version:
#6 0.331 /bin/sh: 1: golangci-lint: not found

What exactly I am doing wrong here?

If I try:

FROM golang:1.16.6-buster
RUN curl -s https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh
    | sh -s v1.45.2

RUN bin/golangci-lint version

I get this detailed output:

docker build -t gotest .
[+] Building 0.9s (6/6) FINISHED
 => [internal] load build definition from Dockerfile                                                                                                     0.0s
 => => transferring dockerfile: 37B                                                                                                                      0.0s
 => [internal] load .dockerignore                                                                                                                        0.0s
 => => transferring context: 2B                                                                                                                          0.0s
 => [internal] load metadata for docker.io/library/golang:1.16.6-buster                                                                                  0.5s
 => [1/3] FROM docker.io/library/golang:1.16.6-buster@sha256:f3923dc5a92a237db0f07a924a238a8a4a711e3b77a7b5bdb1b526e107dcb9d4                            0.0s
 => CACHED [2/3] RUN curl -s https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh    | sh -s v1.45.2                               0.0s
 => ERROR [3/3] RUN bin/golangci-lint version                                                                                                            0.2s
------
 > [3/3] RUN bin/golangci-lint version:
#6 0.214 /bin/sh: 1: bin/golangci-lint: not found
------
executor failed running [/bin/sh -c bin/golangci-lint version]: exit code: 127

Trying:

FROM golang:1.16.6-buster
RUN curl -s https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh
    | sh -s v1.45.2

RUN /go/bin/golangci-lint version

Output:

docker build .
[+] Building 1.7s (7/7) FINISHED
 => [internal] load build definition from Dockerfile                                                                                                     0.0s
 => => transferring dockerfile: 212B                                                                                                                     0.0s
 => [internal] load .dockerignore                                                                                                                        0.0s
 => => transferring context: 32B                                                                                                                         0.0s
 => [internal] load metadata for docker.io/library/golang:1.16.6-buster                                                                                  1.3s
 => [auth] library/golang:pull token for registry-1.docker.io                                                                                            0.0s
 => [1/3] FROM docker.io/library/golang:1.16.6-buster@sha256:f3923dc5a92a237db0f07a924a238a8a4a711e3b77a7b5bdb1b526e107dcb9d4                            0.0s
 => CACHED [2/3] RUN curl -s https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh    | sh -s v1.45.2                               0.0s
 => ERROR [3/3] RUN /go/bin/golangci-lint version                                                                                                        0.3s
------
 > [3/3] RUN /go/bin/golangci-lint version:
#7 0.276 /bin/sh: 1: /go/bin/golangci-lint: not found
------
executor failed running [/bin/sh -c /go/bin/golangci-lint version]: exit code: 127

2

Answers


  1. Chosen as BEST ANSWER

    This is how it worked finally. No binary was getting downloaded due to versions mismatch. I upgraded Go to 1.16 0 and the linter to 1.45.2. Also instead of wget I went for go install which works with this Go version. This got a binary downloaded in the default folder /bin and the CI job was fixed.

    FROM golang:1.16.0-buster
    RUN go install github.com/golangci/golangci-lint/cmd/[email protected]
    RUN ./bin/golangci-lint --version
    

  2. golangci-lint is in bin directory :

    FROM golang:1.16.6-buster
    
    RUN curl -s https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh
        | sh -s v1.45.2
    RUN pwd
    #RUN /go/bin/golangci-lint --version
    

    build output :

    $ docker build --pull --no-cache --tag golang .
    Sending build context to Docker daemon  15.36kB
    Step 1/3 : FROM golang:1.16.6-buster
    1.16.6-buster: Pulling from library/golang
    Digest: sha256:f3923dc5a92a237db0f07a924a238a8a4a711e3b77a7b5bdb1b526e107dcb9d4
    Status: Image is up to date for golang:1.16.6-buster
     ---> 028d102f774a
    Step 2/3 : RUN curl -s https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh    | sh -s v1.45.2
     ---> Running in 4700e3995fcc
    golangci/golangci-lint info checking GitHub for tag 'v1.45.2'
    golangci/golangci-lint info found version: 1.45.2 for v1.45.2/linux/amd64
    golangci/golangci-lint info installed ./bin/golangci-lint
    Removing intermediate container 4700e3995fcc
     ---> 03634ff2897c
    Step 3/3 : RUN bin/golangci-lint --version
     ---> Running in f1348b5de5e2
    golangci-lint has version 1.45.2 built from 8bdc4d3f on 2022-03-24T11:51:26Z
    Removing intermediate container f1348b5de5e2
     ---> dc810407dc0d
    Successfully built dc810407dc0d
    Successfully tagged golang:latest
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search