Skip to content

Latest commit

 

History

History

README.md

DotNetBrowser in Docker

This example demonstrates how to run a DotNetBrowser Avalonia application inside a Docker container, with support for both headless and desktop (X11) modes.

Prerequisites

Configure the License Key

Open MainWindow.axaml.cs and set your license key:

engine = EngineFactory.Create(new EngineOptions.Builder
{
    LicenseKey = "<your_license_key>",
    ...
}.Build());

Build and Run

1. Publish the application

dotnet publish -c Release -o out

2. Build the Docker image

docker build -t dnb-app -f Dockerfile .

3. Run the container

Headless mode

Runs with a virtual X server (Xvfb). Suitable for CI and server environments.

docker run --rm --shm-size=1g dnb-app

When the page loads, you should see the title printed to the console:

Title: Google

Desktop mode (Linux with X11)

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:root

Then run the container:

docker run --rm \
  --shm-size=1g \
  -e DISPLAY=$DISPLAY \
  -v /tmp/.X11-unix:/tmp/.X11-unix \
  dnb-app

When you're done, revoke the X server permission:

xhost -local:root

Remote Debugging

The 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-app

Open a shell inside the running container:

docker exec -it <container_id> /bin/bash

Install and start the SSH server inside the container:

apt install -y openssh-server
service ssh start

Create a user for SSH access:

useradd --create-home --shell /bin/bash dnb-app
passwd dnb-app

On the host, forward the remote debugging port:

ssh -L 9222:localhost:9222 -p 2222 dnb-app@localhost

Keep this SSH session open, then navigate to chrome://inspect in Google Chrome on the host to access DevTools.