Overview of Docker Compose and Zabbix Host Ping on Docker Networks
Docker Compose is a powerful tool for defining and running multi-container Docker applications. It allows you to define the services, networks, and volumes that make up your application in a single file, making it easy to spin up and tear down your application stack.
In this article, we will focus on using Docker Compose to set up a Zabbix host for monitoring a container on a separate Docker network. We will cover the key concepts of Docker Compose, Zabbix, and Docker networking, and provide detailed instructions for setting up and testing the host and container on separate Docker networks.
Prerequisites
Before we begin, you will need the following:
- A Linux host machine with Docker and Docker Compose installed
- A basic understanding of Docker and Docker Compose
- A Zabbix server with the ability to add new hosts
Docker Compose and Zabbix Host Ping
To set up a Zabbix host for monitoring a container on a separate Docker network, we will use Docker Compose to define the services and networks for our application. The Zabbix host will be a separate container on its own Docker network, and will use the Zabbix agent to monitor the container on the other network.
Docker Compose File
The Docker Compose file for our application will define two networks: one for the Zabbix host, and one for the container we want to monitor. It will also provide the necessary configuration for the Zabbix host and agent.
version: '3'
services:
zabbix-host:
image: zabbix/zabbix-agent
networks:
- zabbix-net
environment:
- ZABBIX_HOSTNAME=zabbix-host
- ZABBIX_SERVER_HOST=zabbix-server
- ZABBIX_SERVER_PORT=10051
volumes:
- /var/run/docker.sock:/var/run/docker.sock
monitored-container:
image: alpine
networks:
- monitored-net
networks:
zabbix-net:
driver: bridge
monitored-net:
driver: bridge
In this file, we define two services: zabbix-host and monitored-container. The zabbix-host service uses the zabbix/zabbix-agent image, and is connected to the zabbix-net network. The monitored-container service uses the alpine image, and is connected to the monitored-net network.
The zabbix-host service also has several environment variables set:
ZABBIX_HOSTNAME: The hostname of the Zabbix hostZABBIX_SERVER_HOST: The hostname of the Zabbix serverZABBIX_SERVER_PORT: The port that the Zabbix server is listening on
Additionally, the zabbix-host service mounts the Docker socket to the container, allowing the Zabbix agent to monitor the containers on the host machine.
Starting the Application
To start the application, run the following command:
$ docker-compose up -d
This will start the zabbix-host and monitored-container services in detached mode.
Configuring Zabbix
To configure Zabbix to monitor the monitored-container, we will need to add the container as a host in the Zabbix web interface.
- Log in to the Zabbix web interface
- Navigate to
Configuration > Hosts - Click
Create host - Enter the following information:
Host name: The hostname of the Zabbix host (zabbix-host)IP address: The IP address of the Zabbix host (172.18.0.2)DNS name: The DNS name of the Zabbix host (zabbix-host)Agent interfaces: The interface for the Zabbix agent (172.18.0.2)- Click
Add
Zabbix should now be able to monitor the monitored-container using the Zabbix agent on the zabbix-host.
In this article, we have covered the key concepts of Docker Compose, Zabbix, and Docker networking, and provided detailed instructions for setting up and testing a Zabbix host and a monitored container on separate Docker networks using Docker Compose. With this setup, you can easily monitor the containers on your Docker host using Zabbix-.
References
--endarticle--