/
DirectorySecurity Advisories
Sign In
Directory
zig logo

zig

Last changed

Create your Free Account

Be the first to hear about exciting product updates, critical vulnerability alerts, compare alternative images, and more.

Sign Up
Tags
Overview
Provenance
Specifications
SBOM
Vulnerabilities
Advisories

Chainguard Container for zig

Minimal image with zig binary.

Chainguard Containers are regularly-updated, secure-by-default container images.

Download this Container Image

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.

Run It!

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 mutli-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.

WASM

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.

Other WASM Runtimes

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.

What are Chainguard Containers?

Chainguard Containers are minimal container images that are secure by default.

In many cases, the Chainguard Containers tagged as :latest contain only an open-source application and its runtime dependencies. These minimal container images typically do not contain a shell or package manager. Chainguard Containers are built with Wolfi, our Linux undistro 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 -dev variant.

Although the -dev container image variants have similar security features as their more minimal versions, they feature additional software that is typically not necessary in production environments. We recommend using multi-stage builds to leverage the -dev variants, copying application artifacts into a final minimal container that offers a reduced attack surface that won’t allow package installations or logins.

Learn More

To better understand how to work with Chainguard Containers, please visit Chainguard Academy and Chainguard Courses.

In addition to Containers, Chainguard offers VMs and Libraries. Contact Chainguard to access additional products.

Trademarks

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.

Licenses

Chainguard container images contain software packages that are direct or transitive dependencies. The following licenses were found in the "latest" tag of this image:

  • Apache-2.0

  • GCC-exception-3.1

  • GPL-2.0-only

  • GPL-2.0-or-later

  • GPL-3.0-or-later

  • LGPL-2.1-or-later

  • MIT

For a complete list of licenses, please refer to this Image's SBOM.

Software license agreement

Category
application

Safe Source for Open Sourceâ„¢
Media KitContact Us
© 2025 Chainguard. All Rights Reserved.
Private PolicyTerms of Use

Products

Chainguard ContainersChainguard LibrariesChainguard VMs