Zabbix has some instructional materials at Download and install Zabbix for Containers to help you install Zabbix in a Docker container, but I had trouble getting a working system using these materials. While the Zabbix documentation does include everything you need if you already know what you are doing, I don’t have much docker experience and I haven’t installed Zabbix since 2.4 so I had a few false starts before I got something to work. Hopefully my experience can save you some time.
I started with the docker compose-based installation shown in the video guide which creates separate containers for the server, web interface, and database. I had trouble getting that to work properly. Also it seemed unnecessarily complex for my purposes. I eventually chose to use the appliance image which includes the server, web interface, and database in one container. When I installed per Zabbix manual instructions I got an alpine-based container. I had trouble setting the time zone in this. So I chose an ubuntu-based appliance and everything worked well. I initially did this in centos 7, but I also tested in Ubuntu 18.04 and it works fine there too. So anyway here’s the step-by-step that worked for me.
For this I assume you already have docker set up. For my Ubuntu test, I used How To Install and Use Docker on Ubuntu 18.04
After you have docker set up, you can start your container like this (read the notes below before executing particularly about –name and PHP_TZ):
docker run --name zabbix-appliance -t -p 10051:10051 -p 80:80 -e PHP_TZ=America\/New_York --restart unless-stopped -d zabbix/zabbix-appliance:ubuntu-4.4-latest
- –name specifies the name of the container. This can be anything you want.
- -t allocates a pseudo-tty. I don’t know if this is necessary or desirable here, but it was included in the instructions in the Zabbix manual.
- -p sets port forwarding rules with the syntax <port on localhost>:<port in container host> meaning that anything sent to <port on localhost> will be forwarded to <port in container>. Zabbix uses port 10051 for receiving communications from agents and etc and we use port 80 to access the web front end.
- -e specifies environment variables to set inside the container. In this case we are setting PHP_TZ to the timezone to be used by php. Choose your time zone from the list of php timezones https://www.php.net/manual/en/timezones.php. Be sure to escape your slashes.
Docker will download the container image from the Zabbix repository and run it. You should now have a running container. To verify:
docker ps
should give an output like this:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d5d758a6528a zabbix/zabbix-appliance:ubuntu-4.4-latest "/sbin/tini -- /usr/…" 2 minutes ago Up 2 minutes 0.0.0.0:80->80/tcp, 0.0.0.0:10051->10051/tcp, 443/tcp zabbix-appliance
You’ll have more rows if you have more containers running.
Now we need to set the timezone inside the container (unless you want to use UTC which is statistically unlikely). Get the container id for your Zabbix appliance (the leftmost column in the output of docker ps. Now start a shell inside the container:
docker exec -ti <your_container_id> /bin/bash
You should now have a shell inside the container. Find your timezone in /usr/share/zoneinfo and note its path. To set the timezone, do:
cp /usr/share/zoneinfo/<your>/<timezone> /etc/localtime
Check the time using the date command. If the date command shows the correct time, exit the shell. If it doesn’t, try again.
exit
You should now be back at your shell outside the container. Restart the container to make sure everything inside the container picks up the correct timezone (not sure if this is strictly necessary in this case, but is necessary in general).
docker restart <your_container_id>
You should now have a working Zabbix appliance with the correct timezone. Direct your web browser to your machine’s hostname or ip address to see the Zabbix web frontend. The default login credentials are Username: Admin and password: zabbix
Enjoy!