Dockerized headless version of Draw.io Desktop v25.0.2
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
-
Multiple fonts from
Note
|
Want a new font package, modify the Dockerfile to install the missing package.
|
$ docker run -it -w /data -v $(pwd):/data rlespinasse/drawio-desktop-headless
Usage: drawio [options] [input file/folder]
...
$ 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]
...
-
Enable non-root user
-
env HOME need to contains the path of the working directory (can be the same)
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
-
Needed to run drawio as non-root since v24.4.6
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)
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. |
|
XVFB_DISPLAY |
Screen Display setup for XVFB |
|
XVFB_OPTIONS |
Options for Xvfb |
|
ELECTRON_DISABLE_SECURITY_WARNINGS |
Avoid printing electron warning |
|
DRAWIO_DISABLE_UPDATE |
Disable auto-update of Draw.io Desktop |
|
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.
-
Docker image rlespinasse/drawio-export which enhance export capabilities of the Draw.io Desktop Headless docker image,
-
And GitHub Action rlespinasse/drawio-export-action which is build on top of drawio-export docker image.
-
Thanks for the community about the workaround docker-image based on Draw.io Desktop.