Last active
November 1, 2017 13:48
-
-
Save tedkulp/80c5c707827556ed74e04bb92d924531 to your computer and use it in GitHub Desktop.
Update containers in docker-compose file
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/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