Last active
January 27, 2023 23:13
-
-
Save derekahn/4aaf4087317d8565b9dcd43aab95e047 to your computer and use it in GitHub Desktop.
Universal server shortcuts 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
# Wrapped these in functions becuase of sudo | |
# Otheriwse you get a warning on every shell init | |
# Cleanup | |
function dp() { sudo docker system prune -f; } | |
# Remove Exited containers | |
function drmex() { sudo docker rm $(sudo docker ps -q -f "status=exited"); } | |
# Get latest container ID | |
function dl() { sudo docker ps -l -q; } | |
# Get process included stop container | |
function dpa() { sudo docker ps -a; } | |
# Shortened docker image | |
function di() { sudo docker image $1; } | |
# Get images | |
function dis() { sudo docker images; } | |
# list dangling images | |
function dilsd() { sudo docker images -f dangling=true; } | |
# Remove dangling images | |
function dirmd() { sudo docker rmi $(sudo docker images -f dangling=true -q); } | |
# Get container IP | |
function dpdip() { sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}'; } | |
# Run interactive container, e.g., $dki base /bin/bash | |
function drit() { sudo docker run -it $1; } | |
# Execute interactive container, e.g., $dex base /bin/bash | |
function dex() { sudo docker exec -it $1; } | |
# Lis all exited containers | |
function dlse() { sudo docker ps -a -f status=exited; } | |
# Execute interactive container, e.g., $dex base /bin/bash | |
function dcu() { sudo docker-compose up; } | |
# Execute interactive container, e.g., $dex base /bin/bash | |
function dcd() { sudo docker-compose down; } | |
# Remove all untagged images | |
function drmtag() { sudo docker rmi $(sudo docker images | grep "^<none>" | awk "{print $3}"); } | |
# Stop and Remove all containers | |
function drmf() { sudo docker stop $(sudo docker ps -a -q) && sudo docker rm $(sudo docker ps -a -q); } | |
# Remove all images | |
function dri() { sudo docker rmi -f $(sudo docker images -q); } | |
# dockerfile build, e.g., $dbu tcnksm/test | |
function dbu() { sudo docker build -t=$1 .; } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment