How to Set Up Zabbix 4 with Docker
This guide provides a clear, step-by-step process for deploying a Zabbix 4 monitoring solution using Docker. By containerizing the different components of Zabbix (database, server, and web interface), you can achieve a modular, scalable, and easy-to-manage setup.
Prerequisites
- Docker installed and running on your system.
- A user with permissions to run Docker commands (e.g., the
ec2-user
in the example). - Remember to change the path below to a directory on your own host machine.
Step 1: Create a Dedicated Docker Network
First, we’ll create a dedicated bridge network for our Zabbix containers. This allows them to communicate with each other using their container names as hostnames, which is more secure and reliable than linking or using IP addresses.
docker network create newbridge
Step 2: Launch the MySQL Database Container
Next, we will launch a MySQL container that will serve as the database for Zabbix. All monitoring data will be stored here.
--name zabbix-db
: Assigns a name to the container.-e MYSQL...
: Sets environment variables to configure the database, including the root password, and a dedicated Zabbix user and password.-v /home/ec2-user/db:/var/lib/mysql
: Mounts a host directory (/home/ec2-user/db
) into the container to persist the database data.--network=newbridge
: Connects the container to our custom network.--restart=unless-stopped
: Ensures the container automatically restarts unless it is manually stopped.-d mysql:latest
: Runs the container in detached mode using the latest official MySQL image.--character-set-server=utf8 --collation-server=utf8_bin
: Sets the default character set and collation required by Zabbix.
docker run --name zabbix-db \
-e MYSQL_ROOT_PASSWORD=password \
-e MYSQL_USER='zabbix' \
-e MYSQL_PASSWORD='password' \
-v /home/ec2-user/db:/var/lib/mysql \
-e MYSQL_DATABASE=zabbix \
--network=newbridge \
--restart=unless-stopped -d mysql:latest \
--character-set-server=utf8 --collation-server=utf8_bin
Note: It may take a few minutes for the database to initialize for the first time.
Step 3: Update MySQL User Authentication Method
Recent versions of MySQL use a different authentication plugin by default. We need to alter the zabbix
user to use the mysql_native_password
method, which is expected by the Zabbix server and web components.
docker exec -it zabbix-db mysql ...
: Executes a command inside the runningzabbix-db
container.-uroot -ppassword
: Logs into MySQL as the root user with the password we set earlier.-e "alter user ..."
: The SQL command to execute.
docker exec -it zabbix-db mysql \
-uroot \
-ppassword mysql \
-e "alter user 'zabbix'@'%' identified with mysql_native_password by 'password';"
Step 4: Launch the Zabbix Server Container
Now we’ll start the Zabbix server, which is the core component that performs the monitoring.
--name zabbix-server
: Names the container.-e DB_SERVER_HOST='zabbix-db'
: Tells the Zabbix server that the database is available at the hostnamezabbix-db
.-e MYSQL_USER='zabbix' & -e MYSQL_PASSWORD='password'
: Provides the database credentials.-p 10050:10050
&-p 10051:10051
: Publishes the Zabbix agent port (10050) and Zabbix trapper port (10051) to the host machine.-d zabbix/zabbix-server-mysql:latest
: Runs the official Zabbix server image for MySQL in detached mode.
docker run --name zabbix-server \
-t \
-e DB_SERVER_HOST='zabbix-db' \
-e MYSQL_USER='zabbix' \
-e MYSQL_PASSWORD='password' \
-p 10050:10050 \
-p 10051:10051 \
--restart=unless-stopped \
--network=newbridge \
-d zabbix/zabbix-server-mysql:latest
Step 5: Launch the Zabbix Web Interface Container
Finally, we’ll deploy the Zabbix web interface, which provides a graphical frontend to view data and configure the system.
--name zabbix-web
: Names the container.-e DB_SERVER_HOST='zabbix-db'
: Specifies the database host.-e ZBX_SERVER_HOST='zabbix-server'
: Specifies the Zabbix server host.-e PHP_TZ='Africa/Lagos'
: Sets the timezone for the web interface. You should change this to your local timezone.-p 80:80
: Maps port 80 in the container to port 80 on the host, making the web interface accessible.-d zabbix/zabbix-web-apache-mysql:latest
: Runs the official Zabbix web interface image for Apache and MySQL.
docker run --name zabbix-web \
-t \
-e DB_SERVER_HOST='zabbix-db' \
-e MYSQL_USER='zabbix' \
-e MYSQL_PASSWORD='password' \
-e ZBX_SERVER_HOST='zabbix-server' \
-e PHP_TZ='Africa/Lagos' \
-p 80:80 \
--restart=unless-stopped \
--network=newbridge \
-d zabbix/zabbix-web-apache-mysql:latest
Step 6: Accessing the Zabbix Frontend
Your Zabbix instance should now be running. You can access it by navigating to your host machine’s IP address or http://localhost
in a web browser.
- Default Username:
Admin
- Default Password:
zabbix
You have successfully deployed Zabbix 4 using Docker!
