From fcda6095c810a0a7a23af35b20f55f678556dd06 Mon Sep 17 00:00:00 2001 From: jcwimer Date: Wed, 3 Feb 2016 18:26:47 +0000 Subject: [PATCH] Kill and remove containers gracefully without error when zero are running --- rails-prod.sh | 6 +++++- rails-worker-prod.sh | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/rails-prod.sh b/rails-prod.sh index 4f42d55..8aaa95f 100755 --- a/rails-prod.sh +++ b/rails-prod.sh @@ -8,6 +8,10 @@ fi docker build -t $1 -f rails-prod-Dockerfile . -docker kill $(docker ps -q) +#Kill and remove containers gracefully without error if none are running +docker ps -a | grep "Exit" | awk '{print $1}' | while read -r id ; do + docker kill $id + docker rm $id +done docker run -h $HOSTNAME --name $1 -d --restart=always --env-file $WRESTLINGDEV_ENV_FILE -v /srv/docker/apache2/logs:/var/log/apache2 -v /etc/localtime:/etc/localtime -p 80:80 -p 443:443 $1 diff --git a/rails-worker-prod.sh b/rails-worker-prod.sh index 79dac19..4e5bd25 100755 --- a/rails-worker-prod.sh +++ b/rails-worker-prod.sh @@ -8,6 +8,10 @@ fi docker build -t $1 -f rails-prod-Dockerfile . -docker kill $(docker ps -q) +#Kill and remove containers gracefully without error if none are running +docker ps -a | grep "Exit" | awk '{print $1}' | while read -r id ; do + docker kill $id + docker rm $id +done docker run -h $HOSTNAME --name $1 -d --restart=always --env-file $WRESTLINGDEV_ENV_FILE -v /etc/localtime:/etc/localtime $1 bundle exec rake jobs:work RAILS_ENV=production \ No newline at end of file