A lightweight, Rust builder image based on Alpine Linux. It is pre-configured with Rustup, Zig, and cargo-zigbuild to facilitate effortless static linking and multi-arch cross-compilation using Docker Buildx.
The image tag matches the underlying Alpine Linux version (e.g., 3.23 corresponds to alpine:3.23).
rustup (Stable, minimal)zig (via apk)cargo-zigbuild (Pre-installed)x86_64-unknown-linux-muslaarch64-unknown-linux-muslTARGETARCH for "Write Once, Build Anywhere".This image is designed to work seamlessly with docker buildx. You can build static binaries for Intel (amd64) and Apple Silicon/AWS Graviton (arm64) from a single Dockerfile without manually specifying targets.
Copy the example below. It automatically detects the target architecture and selects the correct Rust target triple.
# syntax=docker/dockerfile:1
# 1. Build Stage
FROM shimaenaga1123/alpine-rust-zigbuild:3.23 AS builder
# 'TARGETARCH' is automatically passed by docker buildx (e.g., amd64, arm64)
ARG TARGETARCH
WORKDIR /app
COPY . .
# Detect Architecture & Build
RUN case "${TARGETARCH}" in \
"amd64") RUST_TARGET="x86_64-unknown-linux-musl" ;; \
"arm64") RUST_TARGET="aarch64-unknown-linux-musl" ;; \
*) echo "Unsupported arch: ${TARGETARCH}" && exit 1 ;; \
esac && \
echo "Building for target: $RUST_TARGET" && \
# Build utilizing zig for cross-linking
cargo zigbuild --release --target $RUST_TARGET && \
# Standardize binary path for the next stage
cp target/$RUST_TARGET/release/my-app /app/my-binary
# 2. Runtime Stage
FROM alpine:3.23
# The binary is statically linked (musl), so no extra dependencies needed!
COPY --from=builder /app/my-binary /usr/local/bin/my-app
CMD ["my-app"]
Content type
Image
Digest
sha256:9929f2bb1…
Size
533.5 MB
Last updated
9 months ago
docker pull shimaenaga1123/alpine-rust-zigbuild