Skip to content

Instantly share code, notes, and snippets.

@rasgo-cc
Last active May 1, 2019 12:43
Show Gist options
  • Save rasgo-cc/f5e4150d710a310c90d48850e20e3abd to your computer and use it in GitHub Desktop.
Save rasgo-cc/f5e4150d710a310c90d48850e20e3abd to your computer and use it in GitHub Desktop.
Bash functions to build/stop/remove Docker images/containers
#!/bin/bash
DOCKERFILE=Dockerfile.dev
build_image() {
# Uncomment if you don't want to build an image if it already exists
#if [ ! "$(docker image ls | grep $1)" ]; then
echo "Build"
docker build . -t $1 -f $DOCKERFILE
#fi
}
stop_container() {
if [ "$(docker ps -aq -f status=running -f name=$1)" ]; then
echo -ne "Stop "
#docker stop $1
docker kill $1
fi
if [ "$(docker ps -aq -f status=exited -f name=$1)" ]; then
echo -ne "Remove "
docker rm $1
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment