Created
February 5, 2015 23:18
-
-
Save freshjones/b0713263033df8cc9f44 to your computer and use it in GitHub Desktop.
bash script to monitor and do something with docker events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
docker events --filter 'event=start' --filter 'event=stop' | while read event | |
do | |
container_id=`echo $event | sed 's/.*Z\ \(.*\):\ .*/\1/'` | |
echo $container_id | |
ipaddress=`docker inspect --format='{{.NetworkSettings.IPAddress}}' $container_id` | |
port=`docker inspect --format='{{(index (index .NetworkSettings.Ports "80/tcp") 0).HostPort}}' $container_id` | |
domain=`docker inspect --format='{{.Config.Domainname}}' $container_id` | |
host=`docker inspect --format='{{.Config.Hostname}}' $container_id` | |
echo $ipaddress | |
echo $port | |
echo $host.$domain | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Many thanks
My version inspired by yours.