Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Wrapper to allow post-creation hooks for docker guests.
#!/bin/sh
#
# Launch a new docker container.
#
# Execute run-parts against a creation directory, and make both the ID
# and the NAME of the new container availalbe to those scripts via the
# environment.
#
# Steve
# --
#
#
# The directory we'll execute against.
#
dir=/etc/docker.start.d/
#
# Invoke docker to get the ID
#
ID=$(docker run $*)
#
# If the ID is empty then something went wrong
#
if [ -z "$ID" ]; then
echo "Creation failed"
exit 1
fi
#
# Make the ID available in the environment
#
export ID
#
# Find the name of the new guest, and make it available.
#
NAME=$(docker inspect --format '{{ .Name }}' $ID | tr -d /)
export NAME
#
# Execute run-parts, if the directory is present
#
if [ -d "$dir" ] ; then
run-parts "$dir"
fi
#
# Output the ID
#
echo $ID
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment