
This page installs Domoticz and the plugin with Docker, for example on a Raspberry Pi. It builds a custom Domoticz image, based on the official domoticz/domoticz stable image, with the Python modules of the plugin already installed, so the container starts quickly.
The plugin, the Domoticz database and the scripts live in a host folder mapped into the container, so they survive container rebuilds and restarts.
docker compose), see Get Docker.docker group, so you don’t need sudo for every command.domoticz and everything lives under /opt/domoticz on the host; adapt if you use other names.The image build needs the plugin, so clone it first, into the userdata/plugins folder that will be mapped into the container:
mkdir -p /opt/domoticz/userdata/plugins
cd /opt/domoticz/userdata/plugins
git clone --filter=blob:none https://github.com/zigbeefordomoticz/Domoticz-Zigbee.git
The plugin ships both files in its Docker folder. Copy them to /opt/domoticz:
cd /opt/domoticz
cp userdata/plugins/Domoticz-Zigbee/Docker/dockerfile .
cp userdata/plugins/Domoticz-Zigbee/Docker/docker-compose.yml .
The dockerfile builds the custom image: it starts from domoticz/domoticz:stable, sets the time zone (TZ=Europe/Paris, change it if needed), installs a few tools (ping, vim, ssh for git pull), and installs the Python modules listed in the plugin requirements.txt into the Domoticz virtual environment of the image (/opt/venv). This is the virtual environment Domoticz already uses: there is none to create or configure. Use the file of the plugin as is; you only need to rebuild the image when the plugin’s Python requirements change.
The docker-compose.yml runs the container. Adapt it to your installation; it should look like this:
services:
domoticz:
build:
context: .
dockerfile: dockerfile
image: domoticz/domoticz:stable-custom
container_name: domoticz
restart: unless-stopped
# Pass devices to container
devices:
- "/dev/serial/by-id/usb-ITEAD_SONOFF_Zigbee_3.0_USB_Dongle_Plus_V2_20220715103321-if00:/dev/ttyUSB-zigbee"
ports:
- "8080:8080"
- "9440:9440"
volumes:
- ./userdata:/opt/domoticz/userdata
logging:
driver: "journald"
devices: maps the coordinator into the container, as <path on the host>:<path in the container> (see step 4). Not needed for a network coordinator.ports: 8080 is the Domoticz web interface, 9440 the plugin WebUI. Add 443:443 if you use Domoticz over https, and one port per additional plugin instance.volumes: ./userdata (that is /opt/domoticz/userdata) holds the Domoticz database, scripts and plugins. Without it, everything would be lost when the container is rebuilt.ls -l /dev/serial/by-id/
lrwxrwxrwx 1 root root 13 Dec 11 22:19 usb-ITEAD_SONOFF_Zigbee_3.0_USB_Dongle_Plus_V2_20220715103321-if00 -> ../../ttyUSB0
Use this /dev/serial/by-id/… path, which doesn’t change after a reboot, on the host side of devices. The container side is a name of your choice, for example /dev/ttyUSB-zigbee: this is the Serial Port you will give to the plugin.
When the container starts, the Domoticz image runs /opt/domoticz/userdata/customstart.sh if it exists. The plugin provides one, which, the first time a new container starts, reinstalls the tools and the plugin Python modules in the image virtual environment /opt/venv (through Tools/plugin-auto-upgrade.sh). Link it, so that plugin updates bring its updates too:
ln -s /opt/domoticz/userdata/plugins/Domoticz-Zigbee/Tools/customstart.sh /opt/domoticz/userdata/customstart.sh
cd /opt/domoticz
docker compose build
docker compose up -d
Domoticz is then available at http://<host>:8080.
Follow Plugin settings. For a USB coordinator, the Serial Port is the container path chosen in step 4 (/dev/ttyUSB-zigbee in the example). Then open the WebUI at http://<host>:9440/z4d/.
git pull in the plugin folder. The modules are installed in the container: when the container is recreated, customstart.sh installs them again (if that fails on your system, see Keep the Python modules in the userdata volume).Domoticz, or the plugin’s Python requirements: rebuild the image and recreate the container:
cd /opt/domoticz
docker compose build --pull
docker compose up -d
Tools/update_domoticz_docker_container.sh, which rebuilds the image (--rebuild), restarts the container and checks for plugin updates. Its defaults (image domoticz-custom:latest, plugin folder /opt/domoticz/plugins/Domoticz-Zigbee) differ from this page: use --image and --plugin-dir to match your setup, and --dry-run to see what it would do. Run it with --help for all the options.Optional. The setup above, with customstart.sh, is the recommended one: you have nothing to configure, and the image handles Python.
The virtual environment of the image (/opt/venv) is part of the container, not of the volume. When the container is recreated (image update, Reset or project rebuild in Synology Container Manager), the plugin modules are gone, and customstart.sh installs them again when the new container first starts. That first start takes longer, and it only happens when you change the image, typically for a new Domoticz version.
If that reinstallation fails on your system (for example, no network yet when the NAS boots), you can instead keep a virtual environment in the userdata volume. Weigh the trade-off first:
customstart.sh handles that by itself.It works with the plain domoticz/domoticz image, without building a custom one. The commands below use the container name domoticz; adapt them.
Open a shell in the container:
docker exec -it domoticz bash
Create the virtual environment in the volume. The python3 of the image is the one Domoticz uses, so the versions match:
python3 -m venv /opt/domoticz/userdata/venv
Install the plugin modules in it, still from the container shell:
/opt/domoticz/userdata/venv/bin/python3 -m pip install \
-r /opt/domoticz/userdata/plugins/Domoticz-Zigbee/requirements.txt
Do it now, from the shell: with an empty virtual environment, the plugin can’t start, so its WebUI (and its Upgrade button) isn’t available.
Add VIRTUAL_ENV and PATH to the environment of the compose file (on Synology, in the Container Manager project), and remove any PYTHONPATH:
environment:
VIRTUAL_ENV: /opt/domoticz/userdata/venv
# Written in full: Compose would replace $PATH with the PATH of the host
PATH: /opt/domoticz/userdata/venv/bin:/opt/venv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
The virtual environment of the volume comes first in PATH: Domoticz looks for its Python there.
Recreate the container (docker compose up -d) and check the Domoticz log. The plugin writes VIRTUAL_ENV is set to: /opt/domoticz/userdata/venv, then starts normally.
Afterwards:
Detected virtualenv via VIRTUAL_ENV (V2). The update cleans the root folder of the virtual environment (see plugin-auto-upgrade.sh): don’t keep anything of your own in /opt/domoticz/userdata/venv.customstart.sh (step 5) isn’t needed any more. If it stays linked, it reinstalls the modules in this virtual environment each time a new container starts, which is harmless./opt/domoticz/userdata/venv/bin/python3 --version fails, and the plugin doesn’t start. Delete it (rm -rf /opt/domoticz/userdata/venv) and do steps 1 to 3 again. Your Zigbee devices and settings are not in it.docker psdocker exec -it domoticz /bin/bashdocker logs domoticz (or journalctl with the journald logging driver)/opt/venv (see Python virtual environment).