Skip to content

Instantly share code, notes, and snippets.

@pragmasoft-ua
Forked from freshjones/gist:b0713263033df8cc9f44
Last active May 6, 2020 23:59
Show Gist options
  • Save pragmasoft-ua/ff20bd60c1077203df57 to your computer and use it in GitHub Desktop.
Save pragmasoft-ua/ff20bd60c1077203df57 to your computer and use it in GitHub Desktop.
bash script to monitor and do something with docker events
#!/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