Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
@CpuID

This comment has been minimized.

Copy link

CpuID commented Jan 4, 2019

nice one

@phedders

This comment has been minimized.

Copy link

phedders commented Nov 23, 2019

there is also the python docker event service... very nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.