Docker images for building and running Zig applications (Alpine and BusyBox variants).
450
This repository contains Dockerfiles and commands to create a Zig development environment and application containers. Different image options are provided for various use-cases, from development to production.
This image includes Zig and necessary development tools such as curl, jq, xz, git, make, musl-dev, gdb, g++, and llvm.
# STAGE 1: Build the application using the existing zig-development image
FROM digi4care/zig-compiler:latest AS builder
# Zet de werkdirectory in de container
WORKDIR /app
# Kopieer de Zig broncode naar de container
COPY app/src/ ./src/
# Compileer de Zig applicatie
RUN zig build-exe src/main.zig
# STAGE 2: Create a minimal production image
FROM alpine:latest AS production
# Installeer CA-certificaten (voor HTTPS-verbindingen, indien nodig)
RUN apk --no-cache add ca-certificates
# Zet de werkdirectory
WORKDIR /app
# Kopieer het gecompileerde binaire bestand van de builder stage
COPY --from=builder /app/main .
# Stel het entrypoint in voor de container
ENTRYPOINT ["./main"]
This image is suitable for applications that require dynamically linked libraries.
Build the image with the following command:
docker build -t zig-app-alpine -f Dockerfile.alpine .
# STAGE 1: Build the application using the existing zig-development image
FROM digi4care/zig-compiler:latest AS builder
# Zet de werkdirectory in de container
WORKDIR /app
# Kopieer de Zig broncode naar de container
COPY app/src/ ./src/
# Compileer de Zig applicatie
RUN zig build-exe src/main.zig
# STAGE 2: Create a minimal production image
# Only suitable for simple static binaries
FROM busybox:latest AS production
# Zet de werkdirectory
WORKDIR /app
# Kopieer het gecompileerde binaire bestand van de builder stage
COPY --from=builder /app/main .
# Stel het entrypoint in voor de container
ENTRYPOINT ["./main"]
This image is optimized for statically linked executables, which do not require external libraries.
Build the image with the following command:
docker build -t zig-app -f Dockerfile.busybox .
To initialize a new Zig project in the app directory, run the following command:
docker run --rm -v "$(pwd)/app:/app" -w /app digi4care/zig-compiler:latest zig init
To compile a Zig program with the release-fast option, run the following command:
docker run --rm -v "$(pwd)/app:/app" -w /app digi4care/zig-compiler:latest zig build-exe src/main.zig -Drelease-fast
To run the compiled Zig program, use one of the following commands based on the chosen image:
docker run --rm -it zig-app-alpine:latest
docker run --rm -it zig-app-busybox:latest
-v flag to mount the local directory into the container and the -w flag to set the working directory inside the container.Content type
Image
Digest
sha256:d7e251a66…
Size
188.1 MB
Last updated
over 1 year ago
docker pull digi4care/zig-compiler