Skip to content

Docker Deployment Guide

Deploy vito2mqtt in Docker for isolation, reproducibility, and easier management across different Linux hosts.

Prerequisites

  • Docker: 20.10+ (install)
  • Docker Compose: 2.0+ (included with Docker Desktop; on Linux, apt install docker-compose-plugin or docker compose version (Docker v2 plugin, pre-installed with Docker Desktop))
  • Serial device: USB-to-serial adapter (CH340, FTDI, etc.) accessible via /dev/ttyUSB0
  • MQTT broker endpoint: Either Docker-hosted (this guide) or external

Quick Start

1. Clone and Configure

# Clone the repository
git clone https://github.com/fabiankoerner/vito2mqtt.git
cd vito2mqtt

# Create configuration from template
cp .env.example .env

# Edit .env for your environment (optional, defaults work with docker-compose)
nano .env  # or your editor

2. Verify Serial Device

Ensure your USB serial adapter is connected and recognized:

# List USB devices
lsusb

# Find the device path:
# /dev/ttyUSB0 (CH340, Prolific)
# /dev/ttyACM0 (CH340G with Arduino driver, CP2102)
ls -la /dev/tty*

# Try connecting to identify baud rate and protocol
minicom -D /dev/ttyUSB0  # Use Ctrl+A, Q to exit

If using a different device path (e.g., /dev/ttyUSB1), update both: - compose.yml: devices: section - .env: VITO2MQTT_SERIAL_PORT

3. Start Services

# Build vito2mqtt image and start both services (Mosquitto + vito2mqtt)
docker compose up

# Detached mode (runs in background)
docker compose up -d

# View logs
docker compose logs -f         # All services
docker compose logs -f vito2mqtt  # Just the app

The app will automatically attempt to connect to the heating device on startup. Check logs for any connection errors.

4. Verify MQTT Connectivity

From another terminal:

# Subscribe to all vito2mqtt topics and monitor messages
docker exec -it vito2mqtt-mosquitto mosquitto_sub -h localhost -t 'vito2mqtt/#' -v

# Or use the MQTT CLI tool (if installed)
mqtt subscribe --uri mqtt://localhost vito2mqtt/#

# Or from another host on the network:
mqtt subscribe --uri mqtt://192.168.1.10 vito2mqtt/#

You should see telemetry messages appear at the intervals specified in VITO2MQTT_POLLING_*.

Configuration

Environment Variables

See .env.example for all options. Key variables:

Serial Connection

VITO2MQTT_SERIAL_PORT=/dev/ttyUSB0
VITO2MQTT_SERIAL_BAUD_RATE=4800

MQTT Broker

# Docker-hosted (docker-compose)
VITO2MQTT_MQTT__HOST=mosquitto
VITO2MQTT_MQTT__PORT=1883
# MQTT 5 retained-message expiry (bundled mosquitto:2). Use 3.1.1 for a broker
# without MQTT 5.
VITO2MQTT_MQTT__PROTOCOL_VERSION=5

# External broker
VITO2MQTT_MQTT__HOST=192.168.1.100
VITO2MQTT_MQTT__PORT=1883
VITO2MQTT_MQTT__USERNAME=api
VITO2MQTT_MQTT__PASSWORD=secret123

Signal Language

VITO2MQTT_SIGNAL_LANGUAGE=en

Polling (seconds)

VITO2MQTT_POLLING_OUTDOOR=300
VITO2MQTT_POLLING_HOT_WATER=300
VITO2MQTT_POLLING_HEATING_RADIATOR=300

Applying Configuration Changes

# Stop services
docker compose down

# Modify .env
nano .env

# Restart
docker compose up -d

Serial Device Access

The compose.yml uses:

devices:
  - /dev/ttyUSB0:/dev/ttyUSB0

This grants container access to /dev/ttyUSB0 directly. Works for single-machine setups.

If using a different device:

devices:
  - /dev/ttyUSB1:/dev/ttyUSB1  # For /dev/ttyUSB1
  - /dev/ttyACM0:/dev/ttyACM0  # For Arduino-style

For consistent device naming across reboots, define udev rules on the host:

Create /etc/udev/rules.d/99-viessmann.rules:

# Viessmann Optolink adapter (adjust VendorID:ProductID for your hardware)
SUBSYSTEM=="tty", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", \
  SYMLINK+="viessmann", MODE="0666"

Reload rules and reconnect device:

sudo udevadm control --reload-rules
sudo udevadm trigger
ls -la /dev/viessmann

Update configuration:

VITO2MQTT_SERIAL_PORT=/dev/viessmann

Troubleshooting Device Access

If container reports "device not found":

# Check if device exists on host
ls -la /dev/ttyUSB0

# Verify container can access it
docker exec vito2mqtt ls -la /dev/ttyUSB0

# Check permissions
sudo chmod 666 /dev/ttyUSB0

# Or add container user to dialout group (requires container rebuild)

Data Persistence

vito2mqtt stores device state (e.g., legionella treatment timestamps) in a JSON file. In Docker, this is persisted via a named volume:

volumes:
  - vito2mqtt-data:/app/data
environment:
  VITO2MQTT_STORE_PATH: /app/data/store.json

The compose.yml configures this automatically. The state file survives container restarts and image upgrades.

Inspecting or Resetting State

# View the current store contents
docker compose exec vito2mqtt cat /app/data/store.json

# Reset state (removes all stored data)
docker compose down
docker volume rm vito2mqtt_vito2mqtt-data
docker compose up -d

Mosquitto Data Volume

Messages and subscriptions are stored in the named volume mosquitto-data. This persists across container restarts and removals until explicitly deleted.

Volume name prefix

Docker Compose prefixes volume names with the project name (directory name by default). If you cloned into vito2mqtt/, the actual volume names are vito2mqtt_mosquitto-data, vito2mqtt_vito2mqtt-data, etc.

# Inspect volume (prefix matches your project directory name)
docker volume inspect vito2mqtt_mosquitto-data

# List all volumes
docker volume ls

# Delete volume (warning: removes persisted data)
docker volume rm vito2mqtt_mosquitto-data

Monitoring and Debugging

View Logs

# Real-time logs for all services
docker compose logs -f

# Just vito2mqtt (colorized, last 100 lines)
docker compose logs -f vito2mqtt --tail 100

# With timestamps
docker compose logs -f vito2mqtt --timestamps

Check Service Status

# List running containers
docker compose ps

# Show container resource usage (CPU, memory)
docker stats vito2mqtt vito2mqtt-mosquitto

Connect to Container Shell

# Open a shell in the vito2mqtt container (Alpine has sh, not bash)
docker exec -it vito2mqtt sh

# Run a command directly
docker exec vito2mqtt vito2mqtt --version

MQTT Debugging

# Listen to all MQTT messages
docker exec vito2mqtt-mosquitto mosquitto_sub -t '#' -v

# Publish test message
docker exec vito2mqtt-mosquitto mosquitto_pub -t 'test/hello' -m 'world'

# Check broker logs
docker compose logs mosquitto

Resource Limits

The shipped compose.yml sets no resource limits. To cap CPU or memory, add a deploy block to the vito2mqtt service:

deploy:
  resources:
    limits:
      cpus: '0.5'
      memory: 128M

Memory limits need the memory cgroup. Some hosts disable it at boot (Raspberry Pi OS kernels with cgroup_disable=memory); docker info then warns about missing memory limit support, and the limit has no effect.

Apply changes:

docker compose up -d

Health Monitoring

MQTT is the primary health signal (ADR-011):

  • vito2mqtt/status carries the periodic heartbeat, with a per-group status of ok, error or stale. The broker publishes the retained last will offline there when the app dies or stops answering keepalives.
  • vito2mqtt/{group}/availability turns offline when reads fail or the group turns stale.
mosquitto_sub -h localhost -v -t 'vito2mqtt/status' -t 'vito2mqtt/+/availability'

The image also ships a Docker HEALTHCHECK that runs cosalette-health every 60 s against the health file at /tmp/vito2mqtt-health.json, so docker ps shows healthy or unhealthy. The container turns unhealthy when any group is stale or the health file is older than 180 s:

docker inspect --format '{{.State.Health.Status}}' vito2mqtt

An unhealthy status restarts nothing. When the app cannot recover, it exits with a non-zero code and restart: unless-stopped starts it again:

docker inspect --format '{{.State.ExitCode}} {{.RestartCount}}' vito2mqtt

See Health and recovery for the stale bounds, the exit codes and why a stale group does not restart the app.

Production Setup

Reverse Proxy (Nginx/Caddy)

If exposing MQTT to the network (not recommended without auth):

# Nginx (TCP reverse proxy, not HTTP)
upstream mqtt {
  server 192.168.1.100:1883;
}

server {
  listen 1883;
  proxy_pass mqtt;
}

Better: Keep MQTT internal and use firewall rules.

Authentication

Enable Mosquitto authentication by creating a config file:

Create mosquitto.conf:

allow_anonymous false
password_file /mosquitto/config/passwd
listener 1883 0.0.0.0

Create password file:

docker run --rm -it eclipse-mosquitto:2 mosquitto_passwd -c /tmp/passwd user1
# Enter password when prompted

# Copy to host mount
docker cp <container>:/tmp/passwd ./mosquitto/passwd

Update compose.yml:

mosquitto:
  volumes:
    - ./mosquitto/passwd:/mosquitto/config/passwd
    - ./mosquitto.conf:/mosquitto/config/mosquitto.conf
    - mosquitto-data:/mosquitto/data

TLS/SSL

For secure MQTT over TLS:

  1. Obtain certificates (Let's Encrypt, self-signed, etc.)
  2. Configure Mosquitto with TLS listener
  3. Update vito2mqtt config: VITO2MQTT_MQTT__TLS=true

See Mosquitto TLS documentation.

MQTT 5 retained-message expiry

The shipped compose.yml defaults VITO2MQTT_MQTT__PROTOCOL_VERSION to 5, which the bundled eclipse-mosquitto:2 supports. An external broker without MQTT 5 needs VITO2MQTT_MQTT__PROTOCOL_VERSION=3.1.1. See MQTT 5 retained-message expiry for the operator contract.

Updating the Application

Pull Latest Changes

git pull origin main

Rebuild Image

docker compose build --no-cache
docker compose up -d

If the image build fails, check:

docker compose build --no-cache --progress=plain

Database/Migration

vito2mqtt does not use a database. Configuration is stateless MQTT pub/sub.

Stopping and Cleanup

# Stop services (containers persist)
docker compose stop

# Stop and remove containers
docker compose down

# Stop, remove containers, and delete volumes (⚠️ deletes Mosquitto data)
docker compose down -v

# Remove unused images/volumes (cleanup)
docker system prune -a --volumes

Docker Network Modes

The default compose.yml uses bridge networking (networks.vito_network).

Service-to-service communication uses internal DNS: - mosquitto (vito2mqtt connects to mqtt://mosquitto:1883) - vito2mqtt (the app, not externally accessible by name)

Port exposure: Only mosquitto:1883 is published to the host.

Alternative: Host Networking (not recommended):

vito2mqtt:
  network_mode: host

Trade-offs: - ✅ Direct hardware access - ✅ Lower latency - ❌ No service isolation - ❌ Port conflicts possible

Troubleshooting

"Cannot connect to serial device"

# Check device exists on host
ls /dev/ttyUSB*

# Verify compose.yml devices section matches
# Rebuild and restart
docker compose down
docker compose up -d --build

"Cannot connect to MQTT broker"

# Verify Mosquitto is running
docker compose ps
docker logs vito2mqtt-mosquitto

# Check network connectivity
docker exec vito2mqtt ping mosquitto

# Verify environment variables were loaded
docker exec vito2mqtt env | grep VITO2MQTT

High CPU Usage

  • Check polling intervals (VITO2MQTT_POLLING_*)
  • Verify serial connection isn't looping with retries
  • Check MQTT broker performance (docker stats)

Logs Fill Up

Configure log rotation in compose.yml:

logging:
  driver: "json-file"
  options:
    max-size: "10m"
    max-file: "3"  # Keep 3 files, 10 MB each

Advanced Configuration

Multiple Devices

To run multiple vito2mqtt instances, give each instance its own serial device, MQTT topic prefix, MQTT client ID and instance ID:

vito2mqtt-1:
  build: .
  env_file: .env.device1
  devices:
    - /dev/ttyUSB0:/dev/ttyUSB0
  depends_on:
    - mosquitto

vito2mqtt-2:
  build: .
  env_file: .env.device2
  devices:
    - /dev/ttyUSB1:/dev/ttyUSB1
  depends_on:
    - mosquitto

Create separate .env.device1 and .env.device2 files. Set a different topic prefix, client ID and instance ID in each file, for example:

# .env.device1
VITO2MQTT_MQTT__TOPIC_PREFIX=vito2mqtt/boiler1
VITO2MQTT_MQTT__CLIENT_ID=vito2mqtt-boiler1
VITO2MQTT_MQTT__INSTANCE_ID=vito2mqtt_boiler1

Warning

Two instances with the same topic prefix publish to the same topics and overwrite each other's retained messages.

The instance ID (lowercase letters, digits and single underscores, starting with a letter) replaces the app name in the Home Assistant and openHAB discovery IDs. Without it, both instances publish discovery under the same IDs and overwrite each other's Home Assistant entities, and vito2mqtt logs a startup warning because the topic prefix differs from the app name. A single instance can leave it unset. Setting it on an existing instance changes its unique IDs once. Before changing it, note the old Home Assistant discovery topics under homeassistant/.../config. After the change, clear each old retained config by publishing an empty retained payload, then remove the old entities in Home Assistant:

MQTT_HOST='broker.example.com'
OLD_TOPIC='homeassistant/sensor/vito2mqtt_boiler1_temperature/config'
mosquitto_pub -h "$MQTT_HOST" -t "$OLD_TOPIC" -r -n

Repeat the command for every old homeassistant/.../config topic, replacing OLD_TOPIC with the exact topic recorded from your broker. -n sends an empty payload and -r marks it retained, which removes that retained config. Add your broker's authentication options if required.

Deleting entities in Home Assistant alone does not clear their retained MQTT configs, so those entities would return after a reconnect or restart.

External MQTT Broker

To connect to a remote MQTT broker instead of docker-hosted Mosquitto:

services:
  vito2mqtt:
    # Remove depends_on: mosquitto line
    env_file: .env

Update .env:

VITO2MQTT_MQTT__HOST=mqtt.example.com
VITO2MQTT_MQTT__PORT=1883
VITO2MQTT_MQTT__USERNAME=api
VITO2MQTT_MQTT__PASSWORD=secret

Remove or comment out the mosquitto service from compose.yml.

Build Arguments

Customize image builds with build arguments (e.g., Python version):

services:
  vito2mqtt:
    build:
      context: .
      dockerfile: Dockerfile
      args:
        PYTHON_VERSION: "3.14"  # Build argument (not yet implemented)

See Also