Image Overview: static
stable
cgr.dev/chainguard/static
Tags | Aliases |
---|---|
latest |
|
latest-glibc |
Base image with just enough files to run static binaries!
This image is meant to be used as a base image only, and is otherwise useless. It contains the alpine-baselayout-data
package from Alpine, which is just a set of data files needed to support glibc and musl static binaries at runtime.
This image can be used with ko build
, docker
, etc, but is only suitable for running completely static binaries, such as with go build
with CGO_ENABLED=0
. See musl-dynamic and glibc-dynamic for images with the C standard library included.
Get It!
The image is available on cgr.dev
:
docker pull cgr.dev/chainguard/static:latest
Usage
Here’s an example Dockerfile that builds a Rust static binary and puts it into the static image:
FROM --platform=x86_64 rust:alpine as build
RUN rustup target add x86_64-unknown-linux-musl
RUN echo 'fn main() { println!("Hello"); }' > hello.rs
RUN rustc --target x86_64-unknown-linux-musl hello.rs
FROM cgr.dev/chainguard/static:latest
COPY --from=build /hello /hello
CMD ["/hello"]
To build and run it:
$ docker build -t rusty-cgr --file examples/Dockerfile.rust .
...
$ docker run rusty-cgr
Hello
Note the size!
$ docker images rusty-cgr
REPOSITORY TAG IMAGE ID CREATED SIZE
rusty-cgr latest aff4c01fd4f0 6 minutes ago 6.09MB
And a C static binary:
# syntax=docker/dockerfile:1.4
FROM gcc:latest as build
COPY <<EOF /hello.c
#include <stdio.h>
int main() { printf("Hello!"); }
EOF
RUN cc -static /hello.c -o /hello
FROM cgr.dev/chainguard/static:latest
COPY --from=build /hello /hello
CMD ["/hello"]
To build and run it:
$ docker build -t c-cgr -f examples/Dockerfile.c .
...
$ docker run c-cgr
Hello!
It’s even smaller:
$ docker images c-cgr
REPOSITORY TAG IMAGE ID CREATED SIZE
c-cgr latest f3648380711c About a minute ago 2.88MB
For Go programs, we recommend using ko and setting
the defaultBaseImage
to cgr.dev/chainguard/static
.
Users
The image has a single user nonroot
with uid 65532
, belonging to gid 65532
.