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.
ā š¦ Pull
docker pull casjaysdev/go:latest
Copy
ā š³ Docker
ā Quick one-shot commands
# 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
Copy
ā Long-running container
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
Copy
ā docker-compose
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:
Copy
ā š§ Included tools
ā Go distribution
Binary Purpose goGo compiler and toolchain gofmtStandard formatter (bundled with Go)
ā Linting & static analysis
Tool Purpose golangci-lintMeta-linter ā runs 50+ analysers in one pass staticcheckAdvanced static analyser (SA, QF, ST, S1 checks) govulncheckVulnerability scanner against the Go vuln DB
ā Formatting & imports
Tool Purpose goimportsgofmt + automatic import groupinggofumptStricter formatter used by many golangci-lint configs
ā Testing & benchmarking
Tool Purpose gotestsumStructured test runner ā JUnit/JSON export, better output benchstatStatistically sound comparison of go test -bench runs
ā Debugging & diagnostics
Tool Purpose dlvDelve ā full Go source-level debugger gopsLive process diagnostics ā stacks, GC, process list
ā Code generation
Tool Purpose stringerGenerates String() for iota-based types wireCompile-time dependency injection code generator mockgenInterface mock generator (Uber fork of golang/mock)
ā Protobuf & gRPC
Tool Purpose protocProtocol Buffers compiler (system package) protoc-gen-goProtobuf Go code generator protoc-gen-go-grpcgRPC Go code generator bufModern protobuf toolchain ā lint, format, breaking-change detection
ā DB migrations
Tool Purpose gooseGo-native migration runner ā supports Go and SQL migrations
ā Release & dev loop
Tool Purpose goreleaserCross-compile, sign, publish, and push container images koBuild Go container images without a Dockerfile airLive-reload dev server for iterative development
ā Language server
Tool Purpose goplsOfficial Go language server ā editor integration
ā āļø Environment variables
Variable Default Purpose GOPATH/usr/local/share/goWorkspace; declared as VOLUME GOCACHE/usr/local/share/go/cacheBuild cache (persisted in volume) GOMODCACHE(defaults to $GOPATH/pkg/mod) Module cache CGO_ENABLED0Static builds by default ā override per build GOTOOLCHAINautoAuto-fetch the Go version declared in go.mod TZAmerica/New_YorkOverride 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 ./...
Copy
ā šļø PATH order
/usr/local/go/bin ā /usr/local/bin ā $GOPATH/bin ā ...
Copy
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.
ā š¾ Persistence
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 ...
Copy
Convenience symlinks also resolve to the canonical path:
Symlink Notes /goLegacy Docker convention ā matches the official golang image /root/goGo's default ~/go GOPATH /root/.goHidden variant /root/.local/share/goXDG base-dir variant /data/goCreated at container start
ā š Cross-compile
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 ./...
Copy
Run go tool dist list for the full ~50-target matrix. goreleaser is
pre-installed to orchestrate multi-platform release builds.
ā š ļø Development
ā Prerequisites
Docker (with buildx)
make, bash
ā Build the image locally
git clone https://github.com/casjaysdev/go "$HOME/Projects/github/casjaysdev/go"
cd "$HOME/Projects/github/casjaysdev/go"
docker build --tag casjaysdev/go:test .
Copy
ā Get source files
git clone "https://github.com/casjaysdev/go" \
"$HOME/Projects/github/casjaysdev/go"
Copy
ā š License
MIT
š¤ casjayā
āµ casjaysdevā
š³ Docker Hubā