Last active
November 5, 2020 09:38
-
-
Save jlnarvaez/46c442ca0666480bb41021856e7c09c6 to your computer and use it in GitHub Desktop.
Utils functions for docker
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
# Delete all containers that contains a name passed by argument | |
# (If argument not passed, all containers will be deleted) | |
# Example: dockrm php | |
dockrm() { | |
docker ps --filter name="$1" -aq | xargs docker stop | xargs docker rm | |
} | |
# Exec container that contains a name passed by argument | |
# Example: dockexec php bash | |
# Can execute a command inside container too | |
# Example dockexec php bash "ls /var/www/html" | |
dockexec() { | |
if [ $# -gt 2 ]; then | |
docker exec -it $(docker ps | grep "$1" | awk '{print $1}') $2 -c "$3" | |
fi | |
if [ $# -eq 2 ]; then | |
docker exec -it $(docker ps | grep "$1" | awk '{print $1}') $2 | |
fi | |
} | |
# Stop all containers that contains a name passed by argument | |
# (If argument not passed, all containers will be stopped) | |
# Example: dockstop php | |
dockstop() { | |
docker ps --filter name="$1" -aq | xargs docker stop | |
} | |
# Start all containters that contains a name passed by argument | |
# (If argument not passed, all containers will be started) | |
# Example: dockstart php | |
dockstart() { | |
docker ps --filter name="$1" -aq | xargs docker start | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment