Alex's website

Run golangci-lint locally with Docker

I recently ran into some issues running golangci-lint locally. I suspected it's because I use asdf to manage my different Go versions. I was able to get around that by running the linter with Docker instead. It's unfortunately not very snappy, but it works for my current workflow for now, so I'm chalking that up as a win.

Here's the Docker command I use:

$ docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:latest golangci-lint run

Here comes Claude for the explanation. Hope this helps!

1: --rm: Automatically removes the container when it exits
2: -v $(pwd):/app:
- $(pwd) gets your current directory path
- Maps your local directory to /app in container
- Allows container to see your code
3: -w /app:
- Sets the working directory inside container
- Makes container run commands from /app directory
4: golangci-lint run -v:
- run: Starts the linting process
- -v: Verbose mode, shows more detailed output
- Checks code against rules defined in your .golangci.yml