Sign inSign up

casjaysdev/go

By casjaysdev

•Updated 22 days ago

Docker build files for go

Image
0

10K+

casjaysdev/go repository overview

⁠go

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

⁠🐳 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
⁠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
⁠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:

ā šŸ”§ Included tools

⁠Go distribution
BinaryPurpose
goGo compiler and toolchain
gofmtStandard formatter (bundled with Go)
⁠Linting & static analysis
ToolPurpose
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
ToolPurpose
goimportsgofmt + automatic import grouping
gofumptStricter formatter used by many golangci-lint configs
⁠Testing & benchmarking
ToolPurpose
gotestsumStructured test runner — JUnit/JSON export, better output
benchstatStatistically sound comparison of go test -bench runs
⁠Debugging & diagnostics
ToolPurpose
dlvDelve — full Go source-level debugger
gopsLive process diagnostics — stacks, GC, process list
⁠Code generation
ToolPurpose
stringerGenerates String() for iota-based types
wireCompile-time dependency injection code generator
mockgenInterface mock generator (Uber fork of golang/mock)
⁠Protobuf & gRPC
ToolPurpose
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
ToolPurpose
gooseGo-native migration runner — supports Go and SQL migrations
⁠Release & dev loop
ToolPurpose
goreleaserCross-compile, sign, publish, and push container images
koBuild Go container images without a Dockerfile
airLive-reload dev server for iterative development
⁠Language server
ToolPurpose
goplsOfficial Go language server — editor integration

ā āš™ļø Environment variables

VariableDefaultPurpose
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 ./...

ā šŸ—‚ļø PATH order

/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.


ā šŸ’¾ 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 ...

Convenience symlinks also resolve to the canonical path:

SymlinkNotes
/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 ./...

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 .
⁠Get source files
git clone "https://github.com/casjaysdev/go" \
  "$HOME/Projects/github/casjaysdev/go"

ā šŸ“„ License

MIT


šŸ¤– casjay⁠
⛵ casjaysdev⁠
🐳 Docker Hub⁠

Tag summary

Content type

Image

Digest

sha256:1a7ba475c…

Size

425 MB

Last updated

22 days ago

docker pull casjaysdev/go