Last active
May 1, 2019 12:43
-
-
Save rasgo-cc/f5e4150d710a310c90d48850e20e3abd to your computer and use it in GitHub Desktop.
Bash functions to build/stop/remove Docker images/containers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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