A Docker image that ships the latest stable Go toolchain (fetched from
go.dev at build time) together with a complete set of tools for building,
testing, linting, debugging, and releasing Go projects. The image is based on
Alpine and produces fully static binaries by default (CGO_ENABLED=0); the
CGO build-deps (gcc, musl-dev, openssl-dev, etc.) are still present so
you can opt in per build.
docker pull casjaysdev/go:latest
# build a project (mount source at /app)
docker run --rm -it \
-v "$PWD:/app" -w /app \
casjaysdev/go:latest \
go build ./...
# run tests
docker run --rm -it \
-v "$PWD:/app" -w /app \
casjaysdev/go:latest \
gotestsum ./...
# lint
docker run --rm -it \
-v "$PWD:/app" -w /app \
casjaysdev/go:latest \
golangci-lint run
# interactive shell
docker run --rm -it \
-v "$PWD:/app" -w /app \
casjaysdev/go:latest \
bash -l
docker run -d \
--restart always \
--name casjaysdev-go \
--hostname go \
-e TZ=${TIMEZONE:-America/New_York} \
-v go-state:/usr/local/share/go \
-v "$PWD:/app" -w /app \
casjaysdev/go:latest
# exec into it
docker exec -it casjaysdev-go bash -l
docker exec casjaysdev-go go test ./...
docker exec casjaysdev-go golangci-lint run
docker exec casjaysdev-go goreleaser release --snapshot --clean
services:
go:
image: casjaysdev/go:latest
container_name: casjaysdev-go
hostname: go
environment:
- TZ=America/New_York
volumes:
- go-state:/usr/local/share/go
- .:/app
working_dir: /app
restart: always
volumes:
go-state:
| Binary | Purpose |
|---|---|
go | Go compiler and toolchain |
gofmt | Standard formatter (bundled with Go) |
| Tool | Purpose |
|---|---|
golangci-lint | Meta-linter ā runs 50+ analysers in one pass |
staticcheck | Advanced static analyser (SA, QF, ST, S1 checks) |
govulncheck | Vulnerability scanner against the Go vuln DB |
| Tool | Purpose |
|---|---|
goimports | gofmt + automatic import grouping |
gofumpt | Stricter formatter used by many golangci-lint configs |
| Tool | Purpose |
|---|---|
gotestsum | Structured test runner ā JUnit/JSON export, better output |
benchstat | Statistically sound comparison of go test -bench runs |
| Tool | Purpose |
|---|---|
dlv | Delve ā full Go source-level debugger |
gops | Live process diagnostics ā stacks, GC, process list |
| Tool | Purpose |
|---|---|
stringer | Generates String() for iota-based types |
wire | Compile-time dependency injection code generator |
mockgen | Interface mock generator (Uber fork of golang/mock) |
| Tool | Purpose |
|---|---|
protoc | Protocol Buffers compiler (system package) |
protoc-gen-go | Protobuf Go code generator |
protoc-gen-go-grpc | gRPC Go code generator |
buf | Modern protobuf toolchain ā lint, format, breaking-change detection |
| Tool | Purpose |
|---|---|
goose | Go-native migration runner ā supports Go and SQL migrations |
| Tool | Purpose |
|---|---|
goreleaser | Cross-compile, sign, publish, and push container images |
ko | Build Go container images without a Dockerfile |
air | Live-reload dev server for iterative development |
| Tool | Purpose |
|---|---|
gopls | Official Go language server ā editor integration |
| Variable | Default | Purpose |
|---|---|---|
GOPATH | /usr/local/share/go | Workspace; declared as VOLUME |
GOCACHE | /usr/local/share/go/cache | Build cache (persisted in volume) |
GOMODCACHE | (defaults to $GOPATH/pkg/mod) | Module cache |
CGO_ENABLED | 0 | Static builds by default ā override per build |
GOTOOLCHAIN | auto | Auto-fetch the Go version declared in go.mod |
TZ | America/New_York | Override at run time with -e TZ=... |
Opt into CGO per build without changing the image:
docker run --rm -v "$PWD:/app" -w /app \
-e CGO_ENABLED=1 \
casjaysdev/go:latest \
go build ./...
/usr/local/go/bin ā /usr/local/bin ā $GOPATH/bin ā ...
Baked tools (/usr/local/bin) always take precedence over anything installed
at runtime into $GOPATH/bin, so a volume-mounted Go workspace can never
shadow the image tools.
Go state lives at /usr/local/share/go (declared VOLUME). Mount a named
volume to persist the module cache, build cache, and any go install-ed tools
across container rebuilds:
# named volume (recommended)
docker run -v go-state:/usr/local/share/go ...
# share with the host's own Go workspace
docker run -v ~/go:/usr/local/share/go ...
Convenience symlinks also resolve to the canonical path:
| Symlink | Notes |
|---|---|
/go | Legacy Docker convention ā matches the official golang image |
/root/go | Go's default ~/go GOPATH |
/root/.go | Hidden variant |
/root/.local/share/go | XDG base-dir variant |
/data/go | Created at container start |
With CGO_ENABLED=0 (the default) the Go toolchain cross-compiles pure-Go
binaries with no extra setup:
GOOS=linux GOARCH=arm64 go build -o app-linux-arm64 ./...
GOOS=darwin GOARCH=arm64 go build -o app-darwin-arm64 ./...
GOOS=windows GOARCH=amd64 go build -o app-windows.exe ./...
GOOS=freebsd GOARCH=amd64 go build -o app-freebsd-amd64 ./...
Run go tool dist list for the full ~50-target matrix. goreleaser is
pre-installed to orchestrate multi-platform release builds.
make, bashgit clone https://github.com/casjaysdev/go "$HOME/Projects/github/casjaysdev/go"
cd "$HOME/Projects/github/casjaysdev/go"
docker build --tag casjaysdev/go:test .
git clone "https://github.com/casjaysdev/go" \
"$HOME/Projects/github/casjaysdev/go"
MIT
š¤ casjayā
āµ casjaysdevā
š³ Docker Hubā
Content type
Image
Digest
sha256:1a7ba475cā¦
Size
425 MB
Last updated
22 days ago
docker pull casjaysdev/go