############################################################################### # Helpful Docker commands and code snippets ############################################################################### ### CONTAINERS ### docker stop $(docker ps -a -q) #stop ALL containers docker rm -f $(docker ps -a -q) # remove ALL containers docker rm -f $(sudo docker ps --before="container_id_here" -q) # can also filter # helps with error: 'unexpected end of JSON input' docker rm -f $(docker ps -a -q) # Remove all in one command with --force docker exec -i -t "container_name_here" /bin/bash # Go to container command line # to exit above use 'ctrl p', 'ctrl q' (don't exit or it will be in exited state) docker rm $(docker ps -q -f status=exited) # remove all exited containers ### IMAGES ### # list images and containers docker images | grep "search_term_here" # remove image(s) (must remove associated containers first) docker rmi -f image_id_here # remove image(s) docker rmi -f $(docker images -q) # remove ALL images!!! docker rmi -f $(docker images | grep "^" | awk '{print $3}') # remove all images docker rmi -f $(docker images | grep 'search_term_here' | awk '{print $1}) # ie. "2 days ago" docker rmi -f $(docker images | grep '