Skip to content

Instantly share code, notes, and snippets.

@ap4y
Created September 30, 2014 03:42
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 ap4y/c6735917f8284f1ea516 to your computer and use it in GitHub Desktop.
Save ap4y/c6735917f8284f1ea516 to your computer and use it in GitHub Desktop.
#!/bin/bash
##
## Usage update_production service [image]
##
## Arguments:
## service: carnival-sidekiq. '-production' will be added automatically
## image: redis:latest. Can be empty, in this case image = service:latest
##
##
if [ -z $2 ]; then
$IMAGE = $1:latest
else
$IMAGE = $2
fi
SERVICE = $1-production.service
# Check if there is a container with the same name in state Exited
CONTIANER = $(sudo docker ps -a | grep $SERVICE | grep 'Exited')
echo $CONTAINER
# Pull image
sudo docker pull $IMAGE
# Remove dead container
if [ -n $CONTAINER ]; then
sudo docker rm $SERVICE
fi
# Restart service
sudo systemctl restart $SERVICE
# Clean dangling images
sudo docker rmi $(sudo docker images -q -f 'dangling=true')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment