Skip to content

Instantly share code, notes, and snippets.

@lcwyo
Last active May 22, 2019 11:30
Show Gist options
  • Save lcwyo/70e1035d68ed152e238ea1a66fd5aea4 to your computer and use it in GitHub Desktop.
Save lcwyo/70e1035d68ed152e238ea1a66fd5aea4 to your computer and use it in GitHub Desktop.
bash script to restart & rebuild docker containers running in docker compose. probably not best practice :-|
#!/bin/bash
# restart services in docker-compose
service-restart() {
docker-compose stop $@
docker-compose rm -f -v $@
docker-compose up --force-recreate --no-start $@
docker-compose start $@
}
if [ $# -eq 0 ]; then
echo ""
echo "you must include the name of a docker-compose service"
echo "you must be in a directory where a suitable configuration file in this directory or any parent."
echo "Supported filenames: docker-compose.yml, docker-compose.yaml"
echo ""
exit 1
fi
for f in $PWD/docker-compose.y*; do
if [ -e "$f" ]; then
# echo "supported files found"
service-restart $@
else
echo "you must be in a directory where a suitable configuration file in this directory or any parent."
exit 1
fi
break
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment