This example demonstrates how to run a DotNetBrowser Avalonia application inside a Docker container, with support for both headless and desktop (X11) modes.
- Docker Engine
- .NET 8 SDK
- A DotNetBrowser license key
Open MainWindow.axaml.cs and set your license key:
engine = EngineFactory.Create(new EngineOptions.Builder
{
LicenseKey = "<your_license_key>",
...
}.Build());dotnet publish -c Release -o outdocker build -t dnb-app -f Dockerfile .Runs with a virtual X server (Xvfb). Suitable for CI and server environments.
docker run --rm --shm-size=1g dnb-appWhen the page loads, you should see the title printed to the console:
Title: Google
Passes the host X server to the container so the application window appears on your desktop.
First, allow local connections to your X server:
xhost +local:rootThen run the container:
docker run --rm \
--shm-size=1g \
-e DISPLAY=$DISPLAY \
-v /tmp/.X11-unix:/tmp/.X11-unix \
dnb-appWhen you're done, revoke the X server permission:
xhost -local:rootThe application exposes Chromium DevTools on port 9222. Since DevTools are bound to the container's localhost, use SSH port forwarding to access them from the host.
Start the container with the SSH port published:
docker run -d -p 2222:22 --shm-size=1g dnb-appOpen a shell inside the running container:
docker exec -it <container_id> /bin/bashInstall and start the SSH server inside the container:
apt install -y openssh-server
service ssh startCreate a user for SSH access:
useradd --create-home --shell /bin/bash dnb-app
passwd dnb-appOn the host, forward the remote debugging port:
ssh -L 9222:localhost:9222 -p 2222 dnb-app@localhostKeep this SSH session open, then navigate to chrome://inspect in Google Chrome on the host to access DevTools.