How to Build and Deploy a Zig Application With Docker

By Loong

How to Build and Deploy a Zig Application With Docker

Now, the zig can be install from a package manager. We create a dockerfile to install zig. We use alpine linux to make the docker image as mininal as possiable. We can simply install zig with apk package manager, event it’s only aliveable for testing version.

FROM alpine:edge
# zig is currently only in testing
RUN apk --no-cache add zig --repository=https://dl-cdn.alpinelinux.org/alpine/edge/testing

RUN mkdir -p /opt/app
WORKDIR /opt/app

The is all content we need. It’s so simply just that language. Now, we can use this dockerfile to build our image.

Usage

docker build -t ziglang .
docker run -it --rm ziglang

Go to the application directory and use zig in docker to build and run your application. For example. Create a hello-world program and run it with docker.

echo '
const std = @import("std");

pub fn main() void {
    std.debug.print("Hello, world!\n", .{});
}
' > hello.zig

Now, run your hello-world program.

docker run -it --rm -v $PWD:/opt/app ziglang zig run hello.zig

Reference: docker-zig