Skip to content

Instantly share code, notes, and snippets.

@Ikke
Created February 15, 2015 00:02
Show Gist options
  • Save Ikke/ec123298318aa95b18ab to your computer and use it in GitHub Desktop.
Save Ikke/ec123298318aa95b18ab to your computer and use it in GitHub Desktop.
Script to build docker images, and (re)create a container based on the image
sudo docker build -t $name .
if [[ $? -gt 0 ]]
then
exit $?
fi
echo -n "Image built, recreate container? [Yn] "
read answer
if [[ ${answer,} == n ]]
then
echo "Image created, old container kept."
exit 0
fi
echo "Stopping and removing old container"
sudo docker stop $name 2>&1 > /dev/null
sudo docker rm $name 2>&1 /dev/null
echo done
echo
echo "Creating new container"
sudo docker create --name $name $args $name
echo done
echo
echo -n "Start new container? [Yn] "
read answer
if [[ ${answer,} != n ]]
then
sudo docker start $name
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment