Skip to content

Docker

A Novis application needs only the nvs binary and your files. A container for it is small.

nvs is the compiler, the server, the test runner and the command line tool. One image runs all of them. The command you give chooses one: serve, run, test or check.

Each release publishes an image to the GitHub Container Registry:

Terminal window
docker pull ghcr.io/novis-lang/novis:0.0.6

The commands on this page use the current release, 0.0.6. To use another release, change the tag. You can also build your own image.

The image runs nothing by itself. You always give the command. A docker run with no command prints the help of nvs and exits with code 0.

Tag Changes Use it for
0.0.6 never Production. This tag always means the same build.
0.0 on each patch release of 0.0 Fixes that do not break your program.
latest on each release Trying Novis. Do not deploy it.
sha-abc1234 never One commit of the repository.

There is no 0 tag before version 1.0. Below 1.0, a new minor version such as 0.5 can break your program. A 0 tag would move to it.

latest and 0.0 change when the release is published. That is usually a few minutes after 0.0.6 appears.

Tag Base image Size without nvs
0.0.6 gcr.io/distroless/cc-debian13 about 43 MB
0.0.6-debian debian:trixie-slim about 119 MB

Use the default, 0.0.6. It has no shell and no package manager. The -debian variant has the same nvs and a shell, so you can open a shell in a running container with docker exec. Use it to find a problem, and deploy the default.

Both variants exist for linux/amd64 and linux/arm64. Docker chooses the right one.

Neither image needs the ca-certificates package. nvs contains the Mozilla list of trusted certificates, so outbound TLS works.

Mount your application at /app, and give the path of its entry file to serve:

Terminal window
docker run --rm -p 8000:8000 \
-v "$PWD:/app:ro" -v novis-data:/usr/local/bin/.nvsdata \
ghcr.io/novis-lang/novis:0.0.6 serve /app/public/index.nvs --listen 0.0.0.0:8000

The volume novis-data keeps the compile cache when you remove the container. The data folder explains it.

serve checks every configuration file before it starts, and again at each reload. The file and its folder must not be writable by a group or by everyone. Use chmod go-w to fix that.

When you change the files of a mounted application, run nvs reload in the container. The server then uses the new files at once:

Terminal window
docker exec <container> nvs reload

Deploy a new version shows the whole deploy.

Mount your application read-only, with :ro. Then nvs.toml and the files it includes may belong to your own account on the host. If you mount them writable, they must belong to uid 65532 or to root. Otherwise serve stops with the error E0607.

On Windows, Docker Desktop can show every file of a mounted folder as writable by everyone. Then serve stops with E0607, even with :ro. Copy your application into your own image with COPY instead of mounting it.

services:
app:
image: ghcr.io/novis-lang/novis:0.0.6
command: ["serve", "/app/public/index.nvs", "--listen", "0.0.0.0:8000"]
ports: ["8000:8000"]
volumes:
- ./app:/app:ro
- novis-data:/usr/local/bin/.nvsdata
read_only: true
cap_drop: ["ALL"]
security_opt: ["no-new-privileges:true"]
# A little longer than [server] drain_timeout, which is 30s by default.
stop_grace_period: 35s
volumes:
novis-data:

read_only: true works because nvs writes only to its data folder, and the volume is that folder. The image already runs as the account nonroot, with the uid 65532. cap_drop and no-new-privileges remove the Linux privileges that are left.

The image starts nvs, so each command of nvs is the first word after the image:

Terminal window
# Run a script.
docker run --rm -v "$PWD:/app:ro" ghcr.io/novis-lang/novis:0.0.6 run hello.nvs
# Run the tests in a folder.
docker run --rm -v "$PWD:/app:ro" ghcr.io/novis-lang/novis:0.0.6 test tests/
# Check the types of a program without running it.
docker run --rm -v "$PWD:/app:ro" ghcr.io/novis-lang/novis:0.0.6 check src/main.nvs
# Print the version and the build information.
docker run --rm ghcr.io/novis-lang/novis:0.0.6 --version
docker run --rm ghcr.io/novis-lang/novis:0.0.6 info

The working folder in the image is /app, so hello.nvs above is /app/hello.nvs. If you mount the folder you are in, the paths are the same as on your computer.

Words after the file name go to your program, not to nvs. In run script.nvs --verbose, your program reads --verbose with Core\Cli::arguments.

nvs in the image runs as the uid 65532. A file it creates in a mounted folder belongs to 65532 on your computer too. To keep your own owner, add --user "$(id -u):$(id -g)". Then also pass --data with a folder that your user owns, because the data folder in the image belongs to nonroot.

Download the Linux archive of nvs, or build it from source, as Install shows. Then copy the binary into the image with your application:

FROM debian:trixie-slim
COPY --chmod=0755 nvs /usr/local/bin/nvs
COPY . /app
WORKDIR /app
# A fixed account that is not root, and the data folder that this account owns.
RUN useradd --uid 65532 --no-create-home --shell /usr/sbin/nologin app \
&& install -d -o app -g app -m 0700 /usr/local/bin/.nvsdata
USER app
EXPOSE 8000
ENTRYPOINT ["nvs"]
CMD ["serve", "/app/public/index.nvs", "--listen", "0.0.0.0:8000"]

This image is Debian 13, which has glibc 2.41. Build nvs on a system with the same glibc or an older one, such as Ubuntu 22.04. A binary built on a newer system does not start in this image.

Build the image and run it:

Terminal window
docker build -t shop .
docker run -p 8000:8000 shop

nvs serve listens on 127.0.0.1:8000 when nothing else is set. Inside a container, that address can only be reached from inside the same container. So each command on this page passes --listen 0.0.0.0:8000. Without it, the container runs, but every connection fails.

You can also write listen = ["0.0.0.0:8000"] under [server] in nvs.toml. The --listen option replaces that setting.

/app is the working folder. nvs reads /app/nvs.toml from there, so the configuration in your project is found without --config.

If you pass --config, nvs reads only the files you name. It does not read /app/nvs.toml. To change a few settings for one deployment, name both files. Then the second file replaces the keys it sets:

Terminal window
nvs serve /app/public/index.nvs --config /app/nvs.toml --config /etc/nvs/override.toml

Configuration shows how the files are combined.

A program has the same capabilities in a container as outside one. The container does not grant more, even when it runs as root. Change them in nvs.toml, as Configuration shows.

Keep secrets out of the image. Docker Compose can mount a secret as a file, and nvs.toml reads it with password_file:

[db.main]
driver = "postgres"
host = "db"
password_file = "/run/secrets/db-password"

Keep nvs.toml in the image. Write the settings for one cluster in a ConfigMap, and mount it as a file. This example uses the image from Build your own image:

apiVersion: v1
kind: ConfigMap
metadata:
name: shop-config
data:
override.toml: |
[limits]
memory = "256M"
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: shop
spec:
selector:
matchLabels: { app: shop }
template:
metadata:
labels: { app: shop }
spec:
containers:
- name: app
image: registry.example.com/shop:1.0
args: ["serve", "/app/public/index.nvs",
"--config", "/app/nvs.toml", "--config", "/etc/nvs/override.toml",
"--listen", "0.0.0.0:8000"]
ports: [{ containerPort: 8000 }]
volumeMounts:
- { name: config, mountPath: /etc/nvs, readOnly: true }
volumes:
- { name: config, configMap: { name: shop-config } }

Each key in override.toml replaces the same key in /app/nvs.toml. Every other key keeps its value from the image. Kubernetes writes the file as root, and only root can change it. So nvs serve accepts it.

After you change the ConfigMap, Kubernetes updates the file in each pod. This can take about a minute. nvs serve checks its configuration files every two seconds, and it uses the new values by itself. You do not need to restart the pods.

A few settings are read only when the server starts, such as listen and workers. If you change one of them, restart the pods with kubectl rollout restart deployment/shop.

Do not put a password in a ConfigMap. Put it in a Secret, mount the Secret as a file, and name that file with password_file.

nvs keeps its own files in a data folder: the compile cache, temporary folders, files for your editor and the logs of a service. By default, this is .nvsdata next to the nvs program. In both kinds of image, that is /usr/local/bin/.nvsdata.

The official image already has this folder. It is empty, and only the account nonroot can open it. In your own image, the RUN line above creates it, because the account app cannot create a folder in /usr/local/bin.

Without this folder, nvs prints a warning. It runs without the compile cache, and Core\IO::createTemporaryDirectory throws an error.

The folder is inside the container. When you remove the container, the compile cache is deleted, and the next container compiles every program again. With read_only: true, nvs cannot write to the folder at all. To keep the cache, mount a volume on the data folder:

Terminal window
docker run -p 8000:8000 -v shop-data:/usr/local/bin/.nvsdata shop

A new volume starts with the owner and the permissions of the folder in the image. A folder from your computer works too. It must belong to the uid 65532, and only its owner may write to it. Otherwise nvs prints a warning and does not use it.

You can also pass --data with the full path of another folder. Do this when you start the container with --user and another uid, because that uid cannot open the folder in the image.

Set health_path to give a load balancer a path to check:

[server]
health_path = "/healthz"

The path returns 200 while the server accepts requests. It returns 503 while the server stops. It does not run your program, and it does not check your database.

Neither image contains a program such as curl. So a HEALTHCHECK in a Dockerfile has nothing to run, and neither image has one. Check the path from outside the container. Kubernetes does this itself:

readinessProbe:
httpGet: { path: /healthz, port: 8000 }
livenessProbe:
httpGet: { path: /healthz, port: 8000 }

With Compose, let your reverse proxy check the path, or build your own image with curl in it.

docker stop sends SIGTERM to nvs serve. Both official images set STOPSIGNAL SIGTERM. When the server gets the signal, it does this:

  • It accepts no new connections.
  • If you set [server] health_path, that path returns 503.
  • Each request that is running finishes, and its response is sent.
  • A connection with no request closes at once.
  • When every connection is closed, the process exits.

SIGINT (Ctrl-C) and SIGHUP stop the server in the same way.

The server gives each open connection at most [server] drain_timeout to finish. The default is 30s. Docker waits 10 seconds by default, and then it sends SIGKILL. Kubernetes waits 30 seconds by default. Set the wait a little longer than drain_timeout:

  • Docker: docker stop -t 35 <container>.
  • Compose: stop_grace_period: 35s.
  • Kubernetes: terminationGracePeriodSeconds: 35.

To stop faster, set a shorter drain_timeout, and a wait a little longer than it:

[server]
drain_timeout = "8s"

nvs is the first process in the container (pid 1). It handles SIGTERM itself, so you do not need docker run --init.

Each official image has a signed statement. It says that the release workflow of the Novis repository built this image, and from which commit. This command checks it:

Terminal window
gh attestation verify oci://ghcr.io/novis-lang/novis:0.0.6 --repo novis-lang/novis

The image contains the same nvs as the release archive for Linux. latest and 0.0 are other names for the same image, so the command checks the same statement for them.

The nvs in the official image has its debug information. A backtrace shows the file and the line of each step. Set RUST_BACKTRACE=1 to print one. The first backtrace takes longer, because nvs unpacks the debug information then.