Skip to main content

Zabbix Docker Installation

Victoria Harbour, Hong Kong

See also Update Version for Zabbix 5.4

Alternatives

Introduction

Zabbix provides Docker images for each Zabbix component as portable and self-sufficient containers to speed up deployment and update procedure.

Zabbix components come with MySQL and PostgreSQL database support, Apache2 and Nginx web server support. These images are separated into different images.

Structure

All Zabbix components are available in the following Docker repositories:

  • Zabbix agent - zabbix/zabbix-agent
  • Zabbix server
    • Zabbix server with MySQL database support - zabbix/zabbix-server-mysql
    • Zabbix server with PostgreSQL database support - zabbix/zabbix-server-pgsql
  • Zabbix web-interface
    • Zabbix web-interface based on Apache2 web server with MySQL database support - zabbix/zabbix-web-apache-mysql
    • Zabbix web-interface based on Apache2 web server with PostgreSQL database support - zabbix/zabbix-web-apache-pgsql
    • Zabbix web-interface based on Nginx web server with MySQL database support - zabbix/zabbix-web-nginx-mysql
    • Zabbix web-interface based on Nginx web server with PostgreSQL database support - zabbix/zabbix-web-nginx-pgsql
  • Zabbix proxy
    • Zabbix proxy with SQLite3 database support - zabbix/zabbix-proxy-sqlite3
    • Zabbix proxy with MySQL database support - zabbix/zabbix-proxy-mysql
    • Zabbix Java Gateway - zabbix/zabbix-java-gateway

Configuring your Firewall

We will open the HTTP and HTTPS (80 and 443) port, and the port that will be used by the Zabbix Server and Zabbix agent (port 10051 and 10050). Run the following firewall-cmd commands.

firewall-cmd --add-service={http,https} --permanent
firewall-cmd --add-port={10051/tcp,10050/tcp} --permanent

Now reload the firewalld configuration and check the port.

firewall-cmd --reload
firewall-cmd --list-all

Docker Compose

Zabbix provides compose files also for defining and running multi-container Zabbix components in Docker. These compose files are available in Zabbix docker official repository on github.com. These compose files are added as examples, they are overloaded. For example, they contain proxies with MySQL and SQLite3 support.

There are a few different versions of compose files:

File nameDescription
docker-compose_v3_alpine_mysql_latest.yamlThe compose file runs the latest version of Zabbix 5.0 components on Alpine Linux with MySQL database support.
do Linux with My
docker-compose_v3_alpine_pgsql_latest.yamlThe compose file runs the latest version of Zabbix 5.0 components on Alpine Linux with PostgreSQL database support.
docker-compose_v3_alpine_pgsql_local.yamlThe compose file locally builds the latest version of Zabbix 5.0 and runs Zabbix components on Alpine Linux with PostgreSQL.
docker-compose_v3_centos_mysql_latest.yamlThe compose file runs the latest version of Zabbix 5.0 components on CentOS 7 with MySQL database support.
dowith MySQL da
docker-compose_v3_centos_pgsql_latest.yamlThe compose file runs the latest version of Zabbix 5.0 components on CentOS 7 with PostgreSQL database support.
dowith PostgreS
docker-compose_v3_ubuntu_mysql_latest.yamlThe compose file runs the latest version of Zabbix 5.0 components on Ubuntu 18.04 with MySQL database support.
do04 with MySQL
docker-compose_v3_ubuntu_pgsql_latest.yamlThe compose file runs the latest version of Zabbix 5.0 components on Ubuntu 18.04 with PostgreSQL database support.
docker-compose_v3_ubuntu_pgsql_local.yamlThe compose file locally builds the latest version of Zabbix 5.0 and runs Zabbix components on Ubuntu 18.04 with Postgres.

Installation

Compose files: Are configured to support local storage on a host machine. Docker Compose will create a zbx_env directory in the folder with the compose file when you run Zabbix components using the compose file. The directory will contain the same structure as described above in the Volumes section and directory for database storage.

There are also volumes in read-only mode for /etc/localtime and /etc/timezone files.

Environment files: In the same directory with compose files on github.com you can find files with default environment variables for each component in compose file. These environment files are named like .env_*type of component*.

# git checkout 5.0
# docker-compose -f ./docker-compose_v3_alpine_mysql_latest.yaml up -d

The command will download latest Zabbix 5.0 images for each Zabbix component and run them in detach mode.

Start by cloning the repository:

cd /opt
git clone https://github.com/mpolinowski/zabbix-docker.git
cd zabbix-docker

Check all Dotfiles inside the directory - the following contain the login for the database you want to use CHANGE THEM IN PRODUCTION:

  • .MYSQL_PASSWORD

  • .MYSQL_ROOT_PASSWORD

  • .MYSQL_USER

  • .POSTGRES_PASSWORD

  • .POSTGRES_USER

If you want to use Zabbix with PostgreSQL based on Alpine LINUX images you have two choices:

  1. docker-compose_v3_alpine_pgsql_latest.yaml
  2. docker-compose_v3_alpine_pgsql_local.yaml

The first one downloads the latest version from DockerHUB. The second downloads the base images (Alpine LINUX) from DockerHUB and builds the Zabbix images for you locally from source.

You can run them in Docker Compose with:

docker-compose -f docker-compose_v3_alpine_pgsql_latest.yaml up  #check run
docker-compose -f docker-compose_v3_alpine_pgsql_latest.yaml up -d #run detached

The Zabbix web interface is now available on port 80 on your hosts IP address. The default login Admin/zabbix can be changed under Administration / Users. Change your Login!:

Zabbix Installation with Docker

Connecting the Agent

The Zabbix Agent installed inside the Docker container is pointing to 127.0.0.1. That is why you will see the following error message:

Get value from agent failed: cannot connect to [[127.0.0.1]:10050]: [111] Connection refused
Zabbix agent is not available (for 3m)

We instead have to point it to the IP address the Agent container has inside the Docker network. For this type the following command to list all running containers and copy the container ID of zabbix/zabbix-agent:alpine-5.0-latest:

docker ps

CONTAINER ID IMAGE COMMAND
6315816b12ed zabbix/zabbix-agent:alpine-5.0-latest "/sbin/tini -- /usr/…"

We can now inspect the container via it's ID 6315816b12ed and see what IP address was assigned to it:

docker inspect 6315816b12ed

The IP is 172.16.239.7 in my case:

"Networks": {
"zabbix-docker_zbx_net_backend": {
"IPAMConfig": null,
"Links": [
"zabbix-docker_zabbix-server_1:zabbix-docker_zabbix-server_1",
"zabbix-docker_zabbix-server_1:zabbix-server",
"zabbix-docker_zabbix-server_1:zabbix-server_1"
],
"Aliases": [
"zabbix-agent-alpine",
"zabbix-agent-passive",
"zabbix-agent",
"6315816b12ed"
],
"NetworkID": "b44fc5350c64f8f39a111ce2a7b8a89628700cf2a52ff2469a5c260669b8d997",
"EndpointID": "815e1dcc4d1f7ee968fdf9e1e142bf27a2c2291843ceaaba15bfb4f86fa79c3c",
"Gateway": "172.16.239.1",
"IPAddress": "172.16.239.7",
"IPPrefixLen": 24,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:10:ef:07",
"DriverOpts": null
}
}

Copy this IP address and past it into the Zabbix Server host configuration - overwriting 127.0.0.1:

Zabbix Installation with Docker

To have this change take effect we need to refresh the configuration cache:

docker exec -ti cad2dbddafd9 /bin/bash
zabbix_server -R config_cache_reload

#or for short:

docker exec -ti cad2dbddafd9 zabbix_server -R config_cache_reload

Where cad2dbddafd9 is the container ID of my instance of zabbix/zabbix-server-pgsql:alpine-5.0-latest. The availability should switch from red to green as soon as you refresh the readout:

Zabbix Installation with Docker

FirewallD

Zabbix Master

firewall-cmd --add-service={http,https} --permanent
firewall-cmd --add-port={8081/tcp,8443/tcp,10050/tcp,10051/tcp,10052/tcp,10061/tcp,10071/tcp,} --permanent
firewall-cmd --reload
firewall-cmd --zone=public --list-all

Zabbix Minion

firewall-cmd --add-service={http,https} --permanent
firewall-cmd --add-port={10051/tcp,10050/tcp} --permanent
firewall-cmd --reload
firewall-cmd --zone=public --list-all

Used Docker Compose File

docker-compose -f /opt/zabbix-docker/docker-compose.yml up
version: '3.5'
services:
zabbix-server:
image: zabbix/zabbix-server-pgsql:alpine-5.0-latest
ports:
- "10051:10051"
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
- ./zbx_env/usr/lib/zabbix/alertscripts:/usr/lib/zabbix/alertscripts:ro
- ./zbx_env/usr/lib/zabbix/externalscripts:/usr/lib/zabbix/externalscripts:ro
- ./zbx_env/var/lib/zabbix/export:/var/lib/zabbix/export:rw
- ./zbx_env/var/lib/zabbix/modules:/var/lib/zabbix/modules:ro
- ./zbx_env/var/lib/zabbix/enc:/var/lib/zabbix/enc:ro
- ./zbx_env/var/lib/zabbix/ssh_keys:/var/lib/zabbix/ssh_keys:ro
- ./zbx_env/var/lib/zabbix/mibs:/var/lib/zabbix/mibs:ro
links:
- postgres-server:postgres-server
- zabbix-java-gateway:zabbix-java-gateway
ulimits:
nproc: 65535
nofile:
soft: 20000
hard: 40000
deploy:
resources:
limits:
cpus: '0.70'
memory: 1G
reservations:
cpus: '0.5'
memory: 512M
env_file:
- .env_db_pgsql
- .env_srv
secrets:
- POSTGRES_USER
- POSTGRES_PASSWORD
depends_on:
- postgres-server
- zabbix-java-gateway
networks:
zbx_net_backend:
ipv4_address: 172.16.239.101
aliases:
- zabbix-server
- zabbix-server-pgsql
- zabbix-server-alpine-pgsql
- zabbix-server-pgsql-alpine
zbx_net_frontend:
ipv4_address: 172.16.238.101
stop_grace_period: 30s
sysctls:
- net.ipv4.ip_local_port_range=1024 65000
- net.ipv4.conf.all.accept_redirects=0
- net.ipv4.conf.all.secure_redirects=0
- net.ipv4.conf.all.send_redirects=0
labels:
com.zabbix.description: "Zabbix server with PostgreSQL database support"
com.zabbix.company: "Zabbix LLC"
com.zabbix.component: "zabbix-server"
com.zabbix.dbtype: "pgsql"
com.zabbix.os: "alpine"

zabbix-proxy-sqlite3:
image: zabbix/zabbix-proxy-sqlite3:alpine-5.0-latest
ports:
- "10061:10051"
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
- ./zbx_env/usr/lib/zabbix/externalscripts:/usr/lib/zabbix/externalscripts:ro
- ./zbx_env/var/lib/zabbix/modules:/var/lib/zabbix/modules:ro
- ./zbx_env/var/lib/zabbix/enc:/var/lib/zabbix/enc:ro
- ./zbx_env/var/lib/zabbix/ssh_keys:/var/lib/zabbix/ssh_keys:ro
- ./zbx_env/var/lib/zabbix/mibs:/var/lib/zabbix/mibs:ro
links:
- zabbix-server:zabbix-server
- zabbix-java-gateway:zabbix-java-gateway
ulimits:
nproc: 65535
nofile:
soft: 20000
hard: 40000
deploy:
resources:
limits:
cpus: '0.70'
memory: 512M
reservations:
cpus: '0.3'
memory: 256M
env_file:
- .env_prx
- .env_prx_sqlite3
depends_on:
- zabbix-java-gateway
networks:
zbx_net_backend:
ipv4_address: 172.16.239.102
aliases:
- zabbix-proxy-sqlite3
- zabbix-proxy-alpine-sqlite3
- zabbix-proxy-sqlite3-alpine
zbx_net_frontend:
ipv4_address: 172.16.238.102
stop_grace_period: 30s
labels:
com.zabbix.description: "Zabbix proxy with SQLite3 database support"
com.zabbix.company: "Zabbix LLC"
com.zabbix.component: "zabbix-proxy"
com.zabbix.dbtype: "sqlite3"
com.zabbix.os: "alpine"

zabbix-proxy-mysql:
image: zabbix/zabbix-proxy-mysql:alpine-5.0-latest
ports:
- "10071:10051"
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
- ./zbx_env/usr/lib/zabbix/externalscripts:/usr/lib/zabbix/externalscripts:ro
- ./zbx_env/var/lib/zabbix/modules:/var/lib/zabbix/modules:ro
- ./zbx_env/var/lib/zabbix/enc:/var/lib/zabbix/enc:ro
- ./zbx_env/var/lib/zabbix/ssh_keys:/var/lib/zabbix/ssh_keys:ro
- ./zbx_env/var/lib/zabbix/mibs:/var/lib/zabbix/mibs:ro
links:
- zabbix-server:zabbix-server
- zabbix-java-gateway:zabbix-java-gateway
ulimits:
nproc: 65535
nofile:
soft: 20000
hard: 40000
deploy:
resources:
limits:
cpus: '0.70'
memory: 512M
reservations:
cpus: '0.3'
memory: 256M
env_file:
- .env_db_mysql_proxy
- .env_prx
- .env_prx_mysql
secrets:
- MYSQL_USER
- MYSQL_PASSWORD
- MYSQL_ROOT_PASSWORD
depends_on:
- mysql-server
- zabbix-java-gateway
networks:
zbx_net_backend:
ipv4_address: 172.16.239.103
aliases:
- zabbix-proxy-mysql
- zabbix-proxy-alpine-mysql
- zabbix-proxy-mysql-alpine
zbx_net_frontend:
ipv4_address: 172.16.238.103
stop_grace_period: 30s
labels:
com.zabbix.description: "Zabbix proxy with MySQL database support"
com.zabbix.company: "Zabbix LLC"
com.zabbix.component: "zabbix-proxy"
com.zabbix.dbtype: "mysql"
com.zabbix.os: "alpine"

zabbix-web-apache-pgsql:
image: zabbix/zabbix-web-apache-pgsql:alpine-5.0-latest
ports:
- "80:8080"
- "443:8443"
links:
- postgres-server:postgres-server
- zabbix-server:zabbix-server
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
- ./zbx_env/etc/ssl/apache2:/etc/ssl/apache2:ro
- ./zbx_env/usr/share/zabbix/modules/:/usr/share/zabbix/modules/:ro
deploy:
resources:
limits:
cpus: '0.70'
memory: 512M
reservations:
cpus: '0.5'
memory: 256M
env_file:
- .env_db_pgsql
- .env_web
secrets:
- POSTGRES_USER
- POSTGRES_PASSWORD
depends_on:
- postgres-server
- zabbix-server
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/"]
interval: 10s
timeout: 5s
retries: 3
start_period: 30s
networks:
zbx_net_backend:
ipv4_address: 172.16.239.104
aliases:
- zabbix-web-apache-pgsql
- zabbix-web-apache-alpine-pgsql
- zabbix-web-apache-pgsql-alpine
zbx_net_frontend:
ipv4_address: 172.16.238.104
stop_grace_period: 10s
sysctls:
- net.core.somaxconn=65535
labels:
com.zabbix.description: "Zabbix frontend on Apache web-server with PostgreSQL database support"
com.zabbix.company: "Zabbix LLC"
com.zabbix.component: "zabbix-frontend"
com.zabbix.webserver: "apache2"
com.zabbix.dbtype: "pgsql"
com.zabbix.os: "alpine"

zabbix-web-nginx-pgsql:
image: zabbix/zabbix-web-nginx-pgsql:alpine-5.0-latest
ports:
- "8081:8080"
- "8443:8443"
links:
- postgres-server:postgres-server
- zabbix-server:zabbix-server
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
- ./zbx_env/etc/ssl/nginx:/etc/ssl/nginx:ro
- ./zbx_env/usr/share/zabbix/modules/:/usr/share/zabbix/modules/:ro
deploy:
resources:
limits:
cpus: '0.70'
memory: 512M
reservations:
cpus: '0.5'
memory: 256M
env_file:
- .env_db_pgsql
- .env_web
secrets:
- POSTGRES_USER
- POSTGRES_PASSWORD
depends_on:
- postgres-server
- zabbix-server
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/"]
interval: 10s
timeout: 5s
retries: 3
start_period: 30s
networks:
zbx_net_backend:
ipv4_address: 172.16.239.105
aliases:
- zabbix-web-nginx-pgsql
- zabbix-web-nginx-alpine-pgsql
- zabbix-web-nginx-pgsql-alpine
zbx_net_frontend:
ipv4_address: 172.16.238.105
stop_grace_period: 10s
sysctls:
- net.core.somaxconn=65535
labels:
com.zabbix.description: "Zabbix frontend on Nginx web-server with PostgreSQL database support"
com.zabbix.company: "Zabbix LLC"
com.zabbix.component: "zabbix-frontend"
com.zabbix.webserver: "nginx"
com.zabbix.dbtype: "pgsql"
com.zabbix.os: "alpine"

zabbix-agent:
privileged: true
image: zabbix/zabbix-agent:alpine-5.0-latest
ports:
- "10050:10050"
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
- ./zbx_env/etc/zabbix/zabbix_agentd.d:/etc/zabbix/zabbix_agentd.d:ro
- ./zbx_env/var/lib/zabbix/modules:/var/lib/zabbix/modules:ro
- ./zbx_env/var/lib/zabbix/enc:/var/lib/zabbix/enc:ro
- ./zbx_env/var/lib/zabbix/ssh_keys:/var/lib/zabbix/ssh_keys:ro
links:
- zabbix-server:zabbix-server
deploy:
resources:
limits:
cpus: '0.2'
memory: 128M
reservations:
cpus: '0.1'
memory: 64M
mode: global
env_file:
- .env_agent
privileged: true
pid: "host"
networks:
zbx_net_backend:
ipv4_address: 172.16.239.106
aliases:
- zabbix-agent
- zabbix-agent-passive
- zabbix-agent-alpine
stop_grace_period: 5s
labels:
com.zabbix.description: "Zabbix agent"
com.zabbix.company: "Zabbix LLC"
com.zabbix.component: "zabbix-agentd"
com.zabbix.os: "alpine"

zabbix-java-gateway:
image: zabbix/zabbix-java-gateway:alpine-5.0-latest
ports:
- "10052:10052"
deploy:
resources:
limits:
cpus: '0.5'
memory: 512M
reservations:
cpus: '0.25'
memory: 256M
env_file:
- .env_java
networks:
zbx_net_backend:
ipv4_address: 172.16.239.107
aliases:
- zabbix-java-gateway
- zabbix-java-gateway-alpine
stop_grace_period: 5s
labels:
com.zabbix.description: "Zabbix Java Gateway"
com.zabbix.company: "Zabbix LLC"
com.zabbix.component: "java-gateway"
com.zabbix.os: "alpine"

mysql-server:
image: mysql:8.0
command:
- mysqld
- --character-set-server=utf8
- --collation-server=utf8_bin
- --default-authentication-plugin=mysql_native_password
volumes:
- ./zbx_env/var/lib/mysql:/var/lib/mysql:rw
env_file:
- .env_db_mysql
secrets:
- MYSQL_USER
- MYSQL_PASSWORD
- MYSQL_ROOT_PASSWORD
stop_grace_period: 1m
networks:
zbx_net_backend:
ipv4_address: 172.16.239.109
aliases:
- mysql-server
- zabbix-database
- mysql-database

postgres-server:
image: postgres:latest
volumes:
- ./zbx_env/var/lib/postgresql/data:/var/lib/postgresql/data:rw
- ./.ZBX_DB_CA_FILE:/run/secrets/root-ca.pem:ro
- ./.ZBX_DB_CERT_FILE:/run/secrets/server-cert.pem:ro
- ./.ZBX_DB_KEY_FILE:/run/secrets/server-key.pem:ro
env_file:
- .env_db_pgsql
secrets:
- POSTGRES_USER
- POSTGRES_PASSWORD
stop_grace_period: 1m
networks:
zbx_net_backend:
ipv4_address: 172.16.239.110
aliases:
- postgres-server
- pgsql-server
- pgsql-database

db_data_mysql:
image: busybox
volumes:
- ./zbx_env/var/lib/mysql:/var/lib/mysql:rw

db_data_pgsql:
image: busybox
volumes:
- ./zbx_env/var/lib/postgresql/data:/var/lib/postgresql/data:rw

networks:
zbx_net_frontend:
driver: bridge
driver_opts:
com.docker.network.enable_ipv6: "false"
ipam:
driver: default
config:
- subnet: 172.16.238.0/24
zbx_net_backend:
driver: bridge
driver_opts:
com.docker.network.enable_ipv6: "false"
internal: true
ipam:
driver: default
config:
- subnet: 172.16.239.0/24

secrets:
MYSQL_USER:
file: ./.MYSQL_USER
MYSQL_PASSWORD:
file: ./.MYSQL_PASSWORD
MYSQL_ROOT_PASSWORD:
file: ./.MYSQL_ROOT_PASSWORD
POSTGRES_USER:
file: ./.POSTGRES_USER
POSTGRES_PASSWORD:
file: ./.POSTGRES_PASSWORD