Skip to content

Instantly share code, notes, and snippets.

@HowardOhMyGod
Created May 29, 2018 12:22
Show Gist options
  • Select an option

  • Save HowardOhMyGod/849dc6af81172788bbd6c8f039d400d5 to your computer and use it in GitHub Desktop.

Select an option

Save HowardOhMyGod/849dc6af81172788bbd6c8f039d400d5 to your computer and use it in GitHub Desktop.
#! /bin/bash
# run container
run () {
docker run --name python -d -p 80:80 python_test
}
# stop and remove container
stop_rm () {
docker stop python
docker rm python
}
# build new image for the latest build
docker build -t python_test .
# check if the production contaier is not running
if [ ! "$(docker ps -q -f name=python)" ];then
# cehck if the container is in docker ps -a
if [ "$(docker ps -aq -f status=exited -f name=python)" ];then
docker rm python
fi
run
else
stop_rm
run
fi
# remove <none>:<none> image in docker images
if [ "$(docker images -f "dangling=true" -q" ];then
docker rmi $(docker images -f "dangling=true" -q)
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment