Skip to content

Instantly share code, notes, and snippets.

@tedkulp
Last active November 1, 2017 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tedkulp/80c5c707827556ed74e04bb92d924531 to your computer and use it in GitHub Desktop.
Save tedkulp/80c5c707827556ed74e04bb92d924531 to your computer and use it in GitHub Desktop.
Update containers in docker-compose file
#!/bin/bash
# Updates containers in a docker-compose file. If passed a name, it will
# just update that container. If no argument is given, it will update
# all the containers in the file. It must be run in a directory where a
# docker-compose command will work and see it's yaml config file.
#
# WARNING: It does remove and create the container, so be careful if you
# care about state that's not saved outside of the container.
#
# Requires docker-compose 1.6+ (Feb 4, 2016)
CONTAINER_NAME=$1
update_container() {
echo "Updating: $1"
PULL_RESULT=`docker-compose pull $1 | grep "Downloaded newer image"`
if [[ ! $? -eq 0 ]]; then
echo "Container $1 is up to date."
else
docker-compose stop $1
docker-compose rm -f $1
docker-compose up -d $1
fi
}
if [[ -z "$CONTAINER_NAME" ]]; then
docker-compose config --services | while read line; do
update_container $line
done
else
update_container $CONTAINER_NAME
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment