Hardened, reproducible Rust base images: runtime, development, builder and cli. Non-root.
743
Hardened, reproducible Rust base images. One Dockerfile per upstream version ships four targets: the production
runtime for a static binary, its development variant, the builder toolchain for a project's production build,
and a cli tooling image a project Makefile invokes.
ghcr.io/gustavofreze/rustlinux/amd64, linux/arm64| Tag | Alias | Purpose |
|---|---|---|
1.100-runtime-1.0.1 | 1.100-runtime | Production base for a static binary. No toolchain, no shell kit. |
1.100-development-1.0.1 | 1.100-development | Local development and Dev Containers: runtime plus the toolchain. |
1.100-builder-1.0.1 | 1.100-builder | Cargo and the musl toolchain for the builder stage of an image. |
1.100-cli-1.0.1 | 1.100-cli | Makefile tooling: Cargo, Clippy, rustfmt, git, bash, curl. |
Every tag is <upstream-minor>-<target>-<version>. There is no bare tag and latest is forbidden.
1.100-runtime stays on 1.100. It moves only when the client re-pulls, which suits cli and local
development.All four are built from one multi-target
Dockerfile, pinned to
rust:1.100.0-alpine3.24 for the toolchain and to alpine:3.24.4 for the runtime.
| Target | Runs as | On top of the base |
|---|---|---|
runtime | app (uid 1000) | Nothing. A pinned Alpine in a single layer, around 13 MB. |
development | app (uid 1000) | runtime plus rustc, Cargo, Clippy, rustfmt, rust-src, gcc, bash, git, curl. |
builder | app (uid 1000) | The upstream toolchain: rustc and Cargo targeting musl, gcc, musl-dev. |
cli | root | builder plus Clippy, rustfmt, bash, curl, git. |
runtime is not built on the Rust image. A release binary targeting musl links statically, so it needs no
interpreter, no standard library on disk, and no compiler runtime.development is built FROM runtime. It runs on a developer machine and is never deployed.builder keeps the whole toolchain on purpose. It is the stage a project compiles its binary in, and the
multi-stage application build discards it.cli stays root so it can write into a bind mount owned by the caller.HEALTHCHECK or exposes a port. These are language bases, not services, so the application that
inherits the runtime declares the health check for the process it actually runs.Every image provides, and no consuming Dockerfile re-declares:
app user (uid 1000), whose home is the /app working directory it owns./etc/ssl/certs/ca-certificates.crt, so a binary that verifies TLS against the
system store works unchanged. A project that trusts a private authority adds the ca-certificates package itself.RUST_BACKTRACE=1 in runtime and development, so a panic prints its backtrace instead of a hint to set the
variable.runtime carries no Cargo, no rustc, no linker, no git, no bash, and no curl,
and the smoke suite asserts each absence.builder links statically against musl, and the smoke
suite proves it by running one in the runtime.CARGO_HOME at the upstream /usr/local/cargo wherever the toolchain ships, so the app user
fetches crates into it with no extra configuration.development. It carries rust-src, so an IDE resolves the standard library, and the
packages a JetBrains backend needs inside the container: gcompat, the X11 rendering libraries, curl, unzip, and
procps.A project consumes the base in two thin files and adds only its own dependencies, code, and tuning:
# syntax=docker/dockerfile:1
FROM gustavofreze/rust:1.100-development-1.0.1
COPY ./ /app
# syntax=docker/dockerfile:1
FROM gustavofreze/rust:1.100-builder-1.0.1 AS builder
COPY Cargo.toml Cargo.lock ./
RUN cargo fetch --locked
COPY ./ ./
RUN cargo build --release --locked --offline
FROM gustavofreze/rust:1.100-runtime-1.0.1
COPY --from=builder --chown=app:app /app/target/release/your-application /app/your-application
CMD ["/app/your-application"]
cargo fetch reads only the manifest and the lock file, so the dependency download is its own layer and a code change
does not repeat it. A crate that links a C library needs that library's development package in the builder stage and
its shared object in the runtime stage, both added by the project.
The development target is the image a Dev Container runs, with the project mounted as its workspace:
{
"image": "gustavofreze/rust:1.100-development-1.0.1",
"remoteUser": "app"
}
The cli image is invoked directly and never appears in a Dockerfile.
To lint the code, run:
docker run --rm -v "$(pwd)":/app gustavofreze/rust:1.100-cli-1.0.1 cargo clippy --all-targets -- -D warnings
To check the formatting, run:
docker run --rm -v "$(pwd)":/app gustavofreze/rust:1.100-cli-1.0.1 cargo fmt --check
The rules that hold across every family live in the usage contract.
No tag is published before it passes the full
gate, on a native linux/amd64 runner and a native
linux/arm64 one:
| Stage | Tool | What it checks |
|---|---|---|
| Lint | hadolint, ShellCheck | Every Dockerfile and every RUN body. |
| Scan | Trivy and Grype | Fixable HIGH and CRITICAL vulnerabilities. |
| Audit | Dockle | The CIS Docker Benchmark. |
| Efficiency | dive | Wasted layer space. |
| Smoke | throwaway containers | The runtime contract, in throwaway containers. |
The smoke suite asserts the non-root user, the pinned toolchain version, linters only where they belong, the absence of a toolchain in the production surface, and a release binary compiled in the builder running in the runtime.
This family carries no accepted risk, so it publishes no OpenVEX analysis and no scanner exemption of any kind. Every scan in the gate runs bare, and what it reports is what the images contain.
To scan a tag yourself, run:
trivy image gustavofreze/rust:1.100-runtime-1.0.1
Content type
Image
Digest
sha256:497b649ca…
Size
365.2 MB
Last updated
3 days ago
docker pull gustavofreze/rust:1.100-development