Public repository for ragedunicorn docker golang images
398

The Go toolchain on Alpine Linux, shipping a pinned upstream Go release decoupled from the Alpine version.
# Pull latest version
docker pull ragedunicorn/golang:latest
# Or pull specific version (see the Tags tab for the available versions)
docker pull ragedunicorn/golang:<go-version>-alpine<alpine-version>-<build>
# Print the Go version
docker run --rm ragedunicorn/golang:latest
# Build the code in the current directory
docker run --rm -v $(pwd):/app ragedunicorn/golang:latest build ./...
On Windows, use the PowerShell form - ${PWD} with braces and the colon
inside the quotes (without braces PowerShell parses $PWD: as a
scope-qualified variable, as in $env:PATH, and rejects the argument):
# Build the code in the current directory
docker run --rm -v "${PWD}:/app" ragedunicorn/golang:latest build ./...
go test -race work out of the box/godocker run --rm -v $(pwd):/app ragedunicorn/golang:latest run main.go
PowerShell:
docker run --rm -v "${PWD}:/app" ragedunicorn/golang:latest run main.go
docker run --rm -v $(pwd):/app -v gocache:/go ragedunicorn/golang:latest build ./...
PowerShell:
docker run --rm -v "${PWD}:/app" -v gocache:/go ragedunicorn/golang:latest build ./...
docker run --rm -v $(pwd):/app -v gocache:/go ragedunicorn/golang:latest test ./...
docker run --rm -v $(pwd):/app -v gocache:/go ragedunicorn/golang:latest test -race ./...
PowerShell:
docker run --rm -v "${PWD}:/app" -v gocache:/go ragedunicorn/golang:latest test ./...
docker run --rm -v "${PWD}:/app" -v gocache:/go ragedunicorn/golang:latest test -race ./...
docker run --rm -v $(pwd):/app -v gocache:/go \
-e CGO_ENABLED=0 \
ragedunicorn/golang:latest build -o app ./cmd/app
PowerShell:
docker run --rm -v "${PWD}:/app" -v gocache:/go `
-e CGO_ENABLED=0 `
ragedunicorn/golang:latest build -o app ./cmd/app
FROM ragedunicorn/golang:latest AS build
WORKDIR /app
COPY --chown=golang:golang . .
RUN CGO_ENABLED=0 go build -o /go/bin/app ./cmd/app
FROM alpine:latest
COPY --from=build /go/bin/app /usr/local/bin/app
ENTRYPOINT ["app"]
This image uses semantic versioning that includes all component versions:
Format: {go_version}-alpine{alpine_version}-{build_number}
X.Y.Z is the Go version, A.B.C the Alpine version:
X.Y.Z-alpineA.B.C-1 - Go X.Y.Z on Alpine A.B.C, build 1X.Y.Z-alpineA.B.C-2 - Rebuild of same versions (bug fixes, security patches)X.Y.Z - Bare Go version, tracking the most recent build of that releaselatest - Most recent stable releaseThe available versions are listed in the Tags tab.
The Go version is pinned per release and updated independently of Alpine. When updates are available through automated dependency management, new releases are created with appropriate version tags.
GOPATH=/go - Pre-created and owned by the golang userGOMODCACHE=/go/pkg/mod - Downloaded modulesGOCACHE=/go/cache - Build cacheGOTOOLCHAIN=local - No implicit toolchain downloadsThe whole cache tree lives under GOPATH, so a single named volume mounted at /go covers both the module cache and the build cache.
The default working directory is /app. Mount your code here:
docker run --rm -v $(pwd):/app ragedunicorn/golang:latest build ./...
PowerShell:
docker run --rm -v "${PWD}:/app" ragedunicorn/golang:latest build ./...
The image is Alpine based, so cgo builds link against musl rather than glibc and will not run on a glibc host. Set CGO_ENABLED=0 for a fully static binary that runs anywhere.
MIT License - See GitHub repository for details.
Content type
Image
Digest
sha256:85985e2f2…
Size
149 MB
Last updated
5 days ago
docker pull ragedunicorn/golang