############################################################################### # Helpful Docker commands and code snippets ############################################################################### # install docker first using directions for installing latest version # https://docs.docker.com/installation/ubuntulinux/#ubuntu-trusty-1404-lts-64-bit # create new docker container, ie. ubuntu docker pull ubuntu:latest # 1x pull down image docker run -i -t ubuntu /bin/bash # drops you into new container as root # list images and containers docker images # all images docker ps -a # all containers docker images | grep # start and attach to container docker start docker attach # stop and remove container docker stop docker rm #stop and remove ALL containers docker stop $(docker ps -a -q) docker rm $(docker ps -a -q) docker rm $(sudo docker ps --before="" -q) # can also filter # Remove all in one command with --force # helps with error: 'unexpected end of JSON input' docker rm -f $(docker ps -a -q) # remove image(s) (must remove associated containers first) docker rmi docker rmi $(docker images | grep ) docker rmi $(docker images | grep "") # ie. "2 days ago" # remove all images docker rmi $(docker images | grep "^" | awk "{print $3}") # remove ALL images!!! docker rmi $(docker images -q) # to only stop exited containers and delete only non-tagged images docker ps --filter 'status=Exited' -a | xargs docker stop docker images --filter "dangling=true" -q | xargs docker rmi # stop and remove containers and associated images with common grep search term docker ps -a --no-trunc | grep "" | awk "{print $1}" | xargs -r --no-run-if-empty docker stop && \ docker ps -a --no-trunc | grep "" | awk "{print $1}" | xargs -r --no-run-if-empty docker rm && \ docker images --no-trunc | grep "" | awk "{print $3}" | xargs -r --no-run-if-empty docker rmi # other great tips: http://www.centurylinklabs.com/15-quick-docker-tips/ # fix fig / docker config: https://gist.github.com/RuslanHamidullin/94d95328a7360d843e52