Guilgo Blog

Notes from my daily work with technology.

After a few months away from the blog, here’s a practical recipe for running Zabbix 6 on Docker. Nothing groundbreaking, but useful if you want a quick monitoring setup without a bare-metal install.

Zabbix is an old friend of mine — alongside Nagios. This time I went back to it not for any particular reason, but because I already had agents configured from a previous install that died when the machine did. Time to bring it back properly.

I assume you already know Docker and have a custom network set up. If not, create one first:

docker network create mynetwork

Create Persistent Volumes

First, create the directories that will be mounted as volumes:

mkdir ~/zabbix-data
mkdir ~/zabbix-data/alertscripts
mkdir ~/zabbix-data/externalscripts
mkdir ~/zabbix-data/export
mkdir ~/zabbix-data/modules
mkdir ~/zabbix-data/enc
mkdir ~/zabbix-data/ssh_keys
mkdir ~/zabbix-data/mibs
mkdir ~/zabbix-data/snmptraps
mkdir -p ~/zabbix-nginx/nginx
mkdir ~/zabbix-nginx/modules
mkdir ~/zabbix-mysql

Launch the Containers

Run each container in order — MySQL first, then the Zabbix components:

# MySQL database
docker run --name mysql-server -t \
      -e MYSQL_DATABASE="zabbix" \
      -e MYSQL_USER="zabbix" \
      -e MYSQL_PASSWORD="mY_Passw0rD8-]" \
      -e MYSQL_ROOT_PASSWORD="|mY_sUp3r-Passw0r-8-]" \
      --network=mynetwork \
      -d mysql:8.0 \
      --character-set-server=utf8 --collation-server=utf8_bin \
      --default-authentication-plugin=mysql_native_password

# Java gateway (for JMX monitoring)
docker run --name zabbix-java-gateway -t \
      --network=mynetwork \
      --restart unless-stopped \
      -d zabbix/zabbix-java-gateway:alpine-6.0-latest

# Zabbix server
docker run --name zabbix-server-mysql -t \
      -e DB_SERVER_HOST="mysql-server" \
      -e MYSQL_DATABASE="zabbix" \
      -e MYSQL_USER="zabbix" \
      -e MYSQL_PASSWORD="mY_Passw0rD8-]" \
      -e MYSQL_ROOT_PASSWORD="|mY_sUp3r-Passw0r-8-]" \
      -e ZBX_JAVAGATEWAY="zabbix-java-gateway" \
      --network=mynetwork \
      -p 10051:10051 \
      --restart unless-stopped \
      -d zabbix/zabbix-server-mysql:alpine-6.0-latest

# Zabbix web frontend (Nginx + MySQL)
docker run --name zabbix-web-nginx-mysql -t \
      -e ZBX_SERVER_HOST="zabbix-server-mysql" \
      -e DB_SERVER_HOST="mysql-server" \
      -e MYSQL_DATABASE="zabbix" \
      -e MYSQL_USER="zabbix" \
      -e MYSQL_PASSWORD="mY_Passw0rD8-]" \
      -e MYSQL_ROOT_PASSWORD="|mY_sUp3r-Passw0r-8-]" \
      --network=mynetwork \
      -p 80:8080 \
      --restart unless-stopped \
      -d zabbix/zabbix-web-nginx-mysql:alpine-6.0-latest

# Zabbix agent (on the same host)
docker run --name zabbix-agent \
      -e ZBX_HOSTNAME="zabbix-server-mysql" \
      -e ZBX_SERVER_HOST="zabbix-server-mysql" \
      --restart=always \
      --network=mynetwork \
      -d zabbix/zabbix-agent:alpine-6.0-latest

Troubleshooting: “dbversion table not found”

On the first run, the Zabbix server may fail with:

Unable to determine current Zabbix database version: the table "dbversion" was not found

This means the database schema wasn’t initialized. Fix it by importing it manually:

# Get the container ID
docker ps

# Connect to the Zabbix server container
docker exec -it <container_id> /bin/bash

# Import the schema
zcat /usr/share/doc/zabbix-server-mysql/create.sql.gz | mysql -uzabbix -p zabbix

After entering the password, reload the web frontend. You should now be able to log in with the default credentials:

  • User: Admin
  • Password: zabbix

Change the default password immediately after first login.

Adding Remote Agents

On each host you want to monitor, install zabbix-agent and edit /etc/zabbix/zabbix_agentd.conf:

ServerActive=<your-zabbix-server-ip>
Hostname=<this-host-name>

Then add the host in the Zabbix web UI under Configuration → Hosts and you’re ready to start monitoring.