Skip to content

rlespinasse/docker-drawio-desktop-headless

Draw.io Desktop Headless docker image

Dockerized headless version of Draw.io Desktop v29.7.8

What it does

Draw.io Desktop exposes a command-line client to allow us to create, check or export diagrams.

Since Draw.io Desktop is a GUI application, we need a GUI environment to run it. And this prevents us to use it for automation in non-GUI environments such as CI tools.

This docker image enables us to run the command-line client in a headless mode by using a configurable X server.

Other minor additions are available

  • Add timeout capability since the application can hang sometimes (due to user action needed in GUI mode)

  • Clear the output log from Electron Security Warning

  • Disable auto-update functionality to avoid unnecessary log

  • Font support via two image variants (see Image Variants)

Getting Started

Run the docker image with your current directory mounted as /data:

$ docker run -it -w /data -v $(pwd):/data rlespinasse/drawio-desktop-headless
Usage: drawio [options] [input file/folder]
...

Export a Draw.io file to PNG:

$ docker run -it -w /data -v $(pwd):/data rlespinasse/drawio-desktop-headless \
      -x -f png my-diagram.drawio

How-to Guides

Run as non-root user

$ docker run -it \
          -u $(id -u):$(id -g) \ (1)
          -e HOME=/data/home -w /data \ (2)
          -v /etc/passwd:/etc/passwd \ (3)
          -v $(pwd):/data rlespinasse/drawio-desktop-headless
Usage: drawio [options] [input file/folder]
...
  1. Enable non-root user

  2. env HOME need to contains the path of the working directory (can be the same)

  3. Needed to run drawio as non-root since v24.4.6

What if env HOME is not set properly?
Fontconfig error: No writable cache directories
A JavaScript error occurred in the main process
Uncaught Exception:
Error: Failed to get 'userData' path
    at initDataListener (/opt/drawio/resources/app.asar/node_modules/electron-store/index.js:15:19)
    at new ElectronStore (/opt/drawio/resources/app.asar/node_modules/electron-store/index.js:48:32)
    at Object.<anonymous> (/opt/drawio/resources/app.asar/src/main/electron.js:15:15)
    at Module._compile (node:internal/modules/cjs/loader:1271:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1326:10)
    at Module.load (node:internal/modules/cjs/loader:1126:32)
    at Module._load (node:internal/modules/cjs/loader:967:12)
    at l._load (node:electron/js2c/asar_bundle:2:13642)
    at node:electron/js2c/browser_init:2:120247
    at node:electron/js2c/browser_init:2:120456
/opt/drawio-desktop/runner.sh: line 4:    15 Trace/breakpoint trap   (core dumped) "${DRAWIO_DESKTOP_EXECUTABLE_PATH:?}" "$@" --no-sandbox --disable-gpu
What if this volume is not set properly?
A JavaScript error occurred in the main process
Uncaught Exception:
SystemError [ERR_SYSTEM_ERROR]: A system error occurred: uv_os_get_passwd returned ENOENT (no such file or directory)
    at new SystemError (node:internal/errors:259:5)
    at new NodeError (node:internal/errors:370:7)
    at Object.userInfo (node:os:365:11)
    at file:///opt/drawio/resources/app.asar/node_modules/atomically/dist/constants.js:10:29
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
    at async node:electron/js2c/browser_init:2:125628
    at async loadESM (node:internal/process/esm_loader:28:7)

Use custom fonts

To use your own fonts (e.g., proprietary or brand fonts), mount a volume to the custom fonts directory:

$ docker run -it -w /data \
      -v $(pwd):/data \
      -v /path/to/my/fonts:/usr/local/share/fonts/custom \
      rlespinasse/drawio-desktop-headless

This works with both the full and minimal variants.

Note
Want to add a system font package instead? Modify the Dockerfile to install the missing package.

Choose an image variant

The docker image is available in two font variants to balance image size and language coverage.

  • Use full (tag: latest) if your diagrams contain Chinese, Japanese, Korean, or other non-Latin scripts.

  • Use minimal (tag: minimal) for Latin-script diagrams only — significantly smaller image.

$ docker pull rlespinasse/drawio-desktop-headless:latest
$ docker pull rlespinasse/drawio-desktop-headless:minimal

See Image Variants for the full list of included font packages.

Use as docker base image

This docker image can be used as the base image to build a higher-level tool upon it.

In addition to running configuration, you have access to

  • DRAWIO_DESKTOP_EXECUTABLE_PATH to have access to the executable path of Draw.io Desktop.

  • DRAWIO_DESKTOP_RUNNER_COMMAND_LINE to run your script instead of the default one.

Used by

Reference

Image Variants

full (default) — tag: latest

Broad Unicode and CJK coverage.

Included font packages:

minimal — tag: minimal

Western fonts only. Significantly smaller image.

Included font packages:

Configuration

Environment Variable Description Default Value

DRAWIO_DESKTOP_COMMAND_TIMEOUT

To prevent Draw.io Desktop process to hang indefinitely.

The value is a floating point number with an optional suffix: 's' for seconds (the default), 'm' for minutes, 'h' for hours or 'd' for days. A duration of 0 disables the associated timeout.

10s

XVFB_DISPLAY

Screen Display setup for XVFB

:42

XVFB_OPTIONS

Options for Xvfb

-nolisten unix (enable non-root run)

ELECTRON_DISABLE_SECURITY_WARNINGS

Avoid printing electron warning

true

DRAWIO_DISABLE_UPDATE

Disable auto-update of Draw.io Desktop

true

SCRIPT_DEBUG_MODE

Enable set -x in internal scripts for debugging purpose

false

Thanks to

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Sponsor this project

 

Contributors