Minimal image with zig binary.
Chainguard Containers are regularly-updated, secure-by-default container images.
For those with access, this container image is available on cgr.dev
:
docker pull cgr.dev/ORGANIZATION/zig:latest
Be sure to replace the ORGANIZATION
placeholder with the name used for your organization's private repository within the Chainguard Registry.
This image should be used to build and test zig applications.
You should not use it as a runtime image.
For runtime images, you can use cgr.dev/chainguard/static
or cgr.dev/chainguard/glibc-dynamic
depending on the type of zig application you build.
The zig tool in this image can be used to setup and build basic zig projects:
$ docker run -it -v $(pwd):/app -w /app cgr.dev/chainguard/zig init-exe
info: Created build.zig
info: Created src/main.zig
info: Next, try `zig build --help` or `zig build run`
$ docker run -it -v $(pwd):/app -w /app cgr.dev/chainguard/zig build run
$ docker run -it -v $(pwd):/app -w /app cgr.dev/chainguard/zig build run
All your codebase are belong to us.
Run `zig build test` to run the tests.
It can also be used in a multi-stage build:
FROM cgr.dev/chainguard/zig:latest-dev as builder
COPY --chown=nonroot . /app
WORKDIR /app
RUN zig build
FROM cgr.dev/chainguard/static
COPY --from=builder /app/zig-out/bin/app /usr/local/bin/app
CMD ["/usr/local/bin/app"]
$ cat << EOF > Dockerfile
FROM cgr.dev/chainguard/zig:latest-dev as builder
WORKDIR /app
COPY . /app
RUN zig build
FROM cgr.dev/chainguard/static
COPY --from=builder /app/zig-out/bin/app /usr/local/bin/app
CMD ["/usr/local/bin/app"]
EOF
$ docker build . -t zigtest
[+] Building 0.4s (12/12) FINISHED
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 305B 0.0s
=> [internal] load metadata for cgr.dev/chainguard/static:latest 0.3s
=> [internal] load metadata for cgr.dev/chainguard/zig:latest-dev 0.2s
=> [internal] load build context 0.0s
=> => transferring context: 1.40kB 0.0s
=> [stage-1 1/2] FROM cgr.dev/chainguard/static@sha256:54b589146d4dbc80a094fcbcd6b09414f3df94cde8ea6d31c44fd02692c58203 0.0s
=> => resolve cgr.dev/chainguard/static@sha256:54b589146d4dbc80a094fcbcd6b09414f3df94cde8ea6d31c44fd02692c58203 0.0s
=> [builder 1/4] FROM cgr.dev/chainguard/zig:latest-dev@sha256:74d1fd19ab5f32a350745c155deaf26684733ac20392e8ca38648bcd0f73db54 0.0s
=> => resolve cgr.dev/chainguard/zig:latest-dev@sha256:74d1fd19ab5f32a350745c155deaf26684733ac20392e8ca38648bcd0f73db54 0.0s
=> CACHED [builder 2/4] COPY --chown=nonroot . /app 0.0s
=> CACHED [builder 3/4] WORKDIR /app 0.0s
=> CACHED [builder 4/4] RUN zig build 0.0s
=> CACHED [stage-1 2/2] COPY --from=builder /app/zig-out/bin/app /usr/local/bin/app 0.0s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => exporting manifest sha256:b2b46fa2142a0a74b56531f700b9052326e19d8f73d576583af26803bf6a32f0 0.0s
=> => exporting config sha256:5f75e89de21e888ce46efef85a14919c0499ef854ed78f0bc9fb0126ed677cb8 0.0s
=> => naming to docker.io/library/zigtest:latest 0.0s
=> => unpacking to docker.io/library/zigtest:latest
$ docker run zigtest
Run `zig build test` to run the tests.
All your codebase are belong to us.
Zig can also be used to build WASM modules.
This Dockerfile can be used to build a WASM image, compatible with Docker's WASM runtime support.
# syntax=docker/dockerfile:1
FROM cgr.dev/chainguard/zig:latest as wasm-builder
WORKDIR /app
COPY --chown=nonroot . /app
RUN zig build-exe src/main.zig -target wasm32-wasi
FROM scratch
COPY --from=wasm-builder /app/main.wasm /main.wasm
ENTRYPOINT [ "/main.wasm" ]
Follow the instructions to enable WASM in docker, then build this and run it:
$ cat << EOF > Dockerfile.wasm
# syntax=docker/dockerfile:1
FROM cgr.dev/chainguard/zig:latest as wasm-builder
WORKDIR /app
COPY --chown=nonroot . /app
RUN zig build-exe src/main.zig -target wasm32-wasi
FROM scratch
COPY --from=wasm-builder /app/main.wasm /main.wasm
ENTRYPOINT [ "/main.wasm" ]
EOF
$ docker build . -t myfirstwasmapp -f Dockerfile.wasm
$ docker run \
--runtime=io.containerd.wasmedge.v1 \
myfirstwasmapp
All your codebase are belong to us.
Run `zig build test` to run the tests.
These wasm binaries can also be run in other WASM runtimes outside of Docker.
Wolfi currently packages wazero, wasmtime, and wasmer.
These can be used together. Here's an example using Zig with Wasmer:
$ docker run -it cgr.dev/chainguard/wolfi-base sh
$ apk add zig wasmer
$ zig init-exe
$ zig build-exe src/main.zig -target wasm32-wasi
$ wasmer run main.wasm
All your codebase are belong to us.
Run `zig build test` to run the tests.
Or in a multi-stage Dockerfile:
FROM cgr.dev/chainguard/zig:latest as builder
WORKDIR /app
RUN zig init-exe
RUN zig build-exe src/main.zig -target wasm32-wasi
FROM cgr.dev/chainguard/wasmer:latest
COPY --from=builder /app/main.wasm /app/main.wasm
CMD ["run", "/app/main.wasm"]
$ cat << EOF > Dockerfile.wasmer
FROM cgr.dev/chainguard/zig:latest as builder
WORKDIR /app
RUN zig init-exe
RUN zig build-exe src/main.zig -target wasm32-wasi
FROM cgr.dev/chainguard/wasmer:latest
COPY --from=builder /app/main.wasm /app/main.wasm
CMD ["run", "/app/main.wasm"]
EOF
$ docker build -t mysecondwasmapp -f Dockerfile.wasmer .
$ docker run mysecondwasmapp
All your codebase are belong to us.
Run `zig build test` to run the tests.
Chainguard's free tier of Starter container images are built with Wolfi, our minimal Linux undistro.
All other Chainguard Containers are built with Chainguard OS, Chainguard's minimal Linux operating system designed to produce container images that meet the requirements of a more secure software supply chain.
The main features of Chainguard Containers include:
For cases where you need container images with shells and package managers to build or debug, most Chainguard Containers come paired with a development, or -dev
, variant.
In all other cases, including Chainguard Containers tagged as :latest
or with a specific version number, the container images include only an open-source application and its runtime dependencies. These minimal container images typically do not contain a shell or package manager.
Although the -dev
container image variants have similar security features as their more minimal versions, they include additional software that is typically not necessary in production environments. We recommend using multi-stage builds to copy artifacts from the -dev
variant into a more minimal production image.
To improve security, Chainguard Containers include only essential dependencies. Need more packages? Chainguard customers can use Custom Assembly to add packages, either through the Console, chainctl
, or API.
To use Custom Assembly in the Chainguard Console: navigate to the image you'd like to customize in your Organization's list of images, and click on the Customize image button at the top of the page.
Refer to our Chainguard Containers documentation on Chainguard Academy. Chainguard also offers VMs and Libraries — contact us for access.
This software listing is packaged by Chainguard. The trademarks set forth in this offering are owned by their respective companies, and use of them does not imply any affiliation, sponsorship, or endorsement by such companies.