Created
October 24, 2022 08:17
-
-
Save carlgrundberg/270cf3d446cbffa5014add6a893e8086 to your computer and use it in GitHub Desktop.
Deploy new version of container without downtime
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
if [ -z "$1" ]; then | |
echo "Service name missing" | |
exit 1 | |
fi | |
service_name="$1" | |
old_container_id=$(docker-compose ps -q $service_name | tail -n1) | |
docker-compose pull $service_name | |
echo "Adding container with new image" | |
docker-compose up -d --scale $service_name=2 --no-recreate $service_name | |
new_container_id=$(docker-compose ps -q $service_name | head -n1) | |
echo "Waiting for new container to be healthy" | |
until [ "`docker inspect -f {{.State.Health.Status}} $new_container_id`" = "healthy" ]; do | |
sleep 1; | |
done; | |
echo "New container is healthy, stopping old container" | |
docker stop $old_container_id | |
echo "Removing old container" | |
docker rm $old_container_id | |
echo "Scaling down to 1 container" | |
docker-compose up -d --scale $service_name=1 --no-recreate $service_name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment