Skip to content

Instantly share code, notes, and snippets.

@andyj
Last active July 22, 2019 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andyj/2b7fe396fbe669f2bf3681eba8b6dcd6 to your computer and use it in GitHub Desktop.
Save andyj/2b7fe396fbe669f2bf3681eba8b6dcd6 to your computer and use it in GitHub Desktop.
Essential Docker commands for .bash_profiles wrapped up as terminal functions
MY_IP=127.0.0.1
#Ubuntu
#MY_IP=$(wget -qO- icanhazip.com)
#MAC
#MY_IP=$(ifconfig en0 | grep "inet 1" | awk '/inet/ { print $2 } ')
echo Current IP: $MY_IP
# Stop all running containers
dstopall(){
docker stop $(docker ps -aq)
}
# Remove all containers
dremovec(){
dstopall
docker rm $(docker ps -aq)
}
# Remove all images
dremovei(){
dstopall
docker rmi $(docker images -q)
}
dbuild() {
source ~/.bash_profile
IPADDRESS="$MY_IP" docker-compose up --build --abort-on-container-exit
}
dbuildclean() {
source ~/.bash_profile
IPADDRESS="$MY_IP" docker-compose down
dremovei
dremovei
IPADDRESS=$MY_IP docker-compose up --force-recreate --build --abort-on-container-exit
}
dockerpurge(){
docker stop $(docker ps -aq)
docker rm $(docker ps -aq)
docker rmi $(docker images -q)
}
dockerrebuild(){
IPADDRESS="$MY_IP" docker-compose up --build --remove-orphans --force-recreate
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment