Running Docker Commands with Administration Scripts
Running Docker Commands with Zabbix Administration Scripts
In this video, I demonstrate how to use administration scripts to manage docker containers.
During the configuration I encounter several issues in which I solve them all.
It's important that the agent, proxy or server process that you want to use to run the script, needs
EnableRemoteCommands=1set in its config file. Then restart the agent, proxy or server service. The specific details of enabled remote commands depend on which version of the agent you are running, and have been covered several times in the previous sections.
If the command you execute needs privileged permissions, then run it with the sudo prefix.
To allow the Zabbix user to use the sudo prefix, add a new line to the sudoers file.
zabbix ALL=(ALL) NOPASSWD: /usr/bin/docker
With these 3 things, I was able to execute docker commands on my host using the administration scripts option.
Those commands were,
sudo docker ps -a sudo docker stats -a --no-stream sudo docker stop nginx2 sudo docker start nginx2
To install docker on Ubuntu 20.04.
sudo apt install docker.io
To list any docker containers,
sudo docker ps -a
To list any docker images that were downloaded to create the containers,
sudo docker images
The example containers I created used in the video were from https://hub.docker.com/r/nginxdemos/hello/
sudo docker run -P -d --name nginx1 nginxdemos/hello sudo docker run -P -d --name nginx1 nginxdemos/hello sudo docker run -P -d --name nginx1 nginxdemos/hello
After experimenting with docker containers and images, and you no longer want them, you can clean up your system and delete them using these commands.
sudo docker rm -f $(sudo docker ps -a -q) sudo docker rmi -f $(sudo docker images -q)
EnableRemoteCommands=1 is set in your agent/proxy config. And you have restarted your agent/proxy after making the change.
If you get the error,
Unsupported item key. Cannot execute script