Skip to content

Instantly share code, notes, and snippets.

@garystafford
Last active April 20, 2025 11:08
Show Gist options
  • Save garystafford/f0bd5f696399d4d7df0f to your computer and use it in GitHub Desktop.
Save garystafford/f0bd5f696399d4d7df0f to your computer and use it in GitHub Desktop.

Revisions

  1. garystafford revised this gist Jun 22, 2018. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions helpful-docker-commands.sh
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,11 @@ 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

    # exec into container
    docker exec -it $(docker container ls | grep '<seach_term>' | awk '{print $1}') sh
    # exec into container on windows with Git Bash
    winpty docker exec -it $(docker container ls | grep '<seach_term>' | awk '{print $1}') sh

    # 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
  2. garystafford revised this gist Nov 16, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions helpful-docker-commands.sh
    Original file line number Diff line number Diff line change
    @@ -22,8 +22,8 @@ docker images | grep "search_term_here"
    docker rmi -f image_id_here # remove image(s)
    docker rmi -f $(docker images -q) # remove ALL images!!!
    docker rmi -f $(docker images | grep "^<none>" | awk '{print $3}') # remove all <none> images
    docker rmi -f $(docker images | grep 'search_term_here' | awk '{print $1}) # i.e. 2 days ago
    docker rmi -f $(docker images | grep '<search_1\|search_2' | awk '{print $1}')
    docker rmi -f $(docker images | grep 'search_term_here' | awk '{print $1}') # i.e. 2 days ago
    docker rmi -f $(docker images | grep 'search_1\|search_2' | awk '{print $1}')

    ### DELETE BOTH IMAGES AND CONTAINERS ###
    docker images && docker ps -a
  3. garystafford revised this gist Nov 16, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion helpful-docker-commands.sh
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,7 @@ docker images | grep "search_term_here"
    docker rmi -f image_id_here # remove image(s)
    docker rmi -f $(docker images -q) # remove ALL images!!!
    docker rmi -f $(docker images | grep "^<none>" | awk '{print $3}') # remove all <none> images
    docker rmi -f $(docker images | grep 'search_term_here' | awk '{print $1}) # ie. "2 days ago"
    docker rmi -f $(docker images | grep 'search_term_here' | awk '{print $1}) # i.e. 2 days ago
    docker rmi -f $(docker images | grep '<search_1\|search_2' | awk '{print $1}')
    ### DELETE BOTH IMAGES AND CONTAINERS ###
  4. garystafford revised this gist Nov 16, 2016. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion helpful-docker-commands.sh
    Original file line number Diff line number Diff line change
    @@ -6,15 +6,18 @@
    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!!!
    @@ -28,10 +31,11 @@ docker images && docker ps -a
    docker ps -a --no-trunc | grep "search_term_here" | awk "{print $1}" | xargs -r --no-run-if-empty docker stop && \
    docker ps -a --no-trunc | grep "search_term_here" | awk "{print $1}" | xargs -r --no-run-if-empty docker rm && \
    docker images --no-trunc | grep "search_term_here" | awk "{print $3}" | xargs -r --no-run-if-empty docker rmi
    # stops only 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
    ### DELETE NETWORKS / VOLUMES ###
    ### DELETE NETWORKS AND VOLUMES ###
    # clean up orphaned volumes
    docker volume rm $(docker volume ls -qf dangling=true)
  5. garystafford revised this gist Nov 16, 2016. 1 changed file with 8 additions and 3 deletions.
    11 changes: 8 additions & 3 deletions helpful-docker-commands.sh
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,6 @@
    ###############################################################################

    ### CONTAINERS ###
    docker ps -a # list all 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
    @@ -15,7 +14,6 @@ docker rm $(docker ps -q -f status=exited) # remove all exited containers

    ### IMAGES ###
    # list images and containers
    docker images # all images
    docker images | grep "search_term_here"
    # remove image(s) (must remove associated containers first)
    docker rmi -f image_id_here # remove image(s)
    @@ -24,7 +22,7 @@ docker rmi -f $(docker images | grep "^<none>" | awk '{print $3}') # remove all
    docker rmi -f $(docker images | grep 'search_term_here' | awk '{print $1}) # ie. "2 days ago"
    docker rmi -f $(docker images | grep '<search_1\|search_2' | awk '{print $1}')
    ### BOTH IMAGES AND CONTAINERS ###
    ### DELETE BOTH IMAGES AND CONTAINERS ###
    docker images && docker ps -a
    # stop and remove containers and associated images with common grep search term
    docker ps -a --no-trunc | grep "search_term_here" | awk "{print $1}" | xargs -r --no-run-if-empty docker stop && \
    @@ -33,6 +31,13 @@ docker images --no-trunc | grep "search_term_here" | awk "{print $3}" | xargs -r
    # stops only 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
    ### DELETE NETWORKS / VOLUMES ###
    # clean up orphaned volumes
    docker volume rm $(docker volume ls -qf dangling=true)
    # clean up orphaned networks
    docker network rm $(docker network ls -q)
    ### NEW IMAGES/CONTAINERS ###
    # create new docker container, ie. ubuntu
    docker pull ubuntu:latest # 1x pull down image
  6. garystafford revised this gist Nov 9, 2016. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion helpful-docker-commands.sh
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,8 @@ docker images | grep "search_term_here"
    docker rmi -f image_id_here # remove image(s)
    docker rmi -f $(docker images -q) # remove ALL images!!!
    docker rmi -f $(docker images | grep "^<none>" | awk '{print $3}') # remove all <none> images
    docker rmi -f $(docker images | grep "search_term_here") # ie. "2 days ago"
    docker rmi -f $(docker images | grep 'search_term_here' | awk '{print $1}) # ie. "2 days ago"
    docker rmi -f $(docker images | grep '<search_1\|search_2' | awk '{print $1}')
    ### BOTH IMAGES AND CONTAINERS ###
    docker images && docker ps -a
  7. garystafford revised this gist Nov 9, 2016. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions helpful-docker-commands.sh
    Original file line number Diff line number Diff line change
    @@ -5,8 +5,8 @@
    ### CONTAINERS ###
    docker ps -a # list all containers
    docker stop $(docker ps -a -q) #stop ALL containers
    docker rm $(docker ps -a -q) # remove ALL containers
    docker rm $(sudo docker ps --before="container_id_here" -q) # can also filter
    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
    @@ -18,10 +18,10 @@ docker rm $(docker ps -q -f status=exited) # remove all exited containers
    docker images # all images
    docker images | grep "search_term_here"
    # remove image(s) (must remove associated containers first)
    docker rmi image_id_here # remove image(s)
    docker rmi $(docker images -q) # remove ALL images!!!
    docker rmi $(docker images -a | grep "^<none>" | awk "{print $3}") # remove all <none> images
    docker rmi $(docker images | grep "search_term_here") # ie. "2 days ago"
    docker rmi -f image_id_here # remove image(s)
    docker rmi -f $(docker images -q) # remove ALL images!!!
    docker rmi -f $(docker images | grep "^<none>" | awk '{print $3}') # remove all <none> images
    docker rmi -f $(docker images | grep "search_term_here") # ie. "2 days ago"

    ### BOTH IMAGES AND CONTAINERS ###
    docker images && docker ps -a
  8. garystafford revised this gist Jul 11, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions helpful-docker-commands.sh
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,7 @@ docker images | grep "search_term_here"
    # remove image(s) (must remove associated containers first)
    docker rmi image_id_here # remove image(s)
    docker rmi $(docker images -q) # remove ALL images!!!
    docker rmi $(docker images | grep "^<none>" | awk "{print $3}") # remove all <none> images
    docker rmi $(docker images -a | grep "^<none>" | awk "{print $3}") # remove all <none> images
    docker rmi $(docker images | grep "search_term_here") # ie. "2 days ago"

    ### BOTH IMAGES AND CONTAINERS ###
    @@ -42,4 +42,4 @@ docker run -i -t ubuntu /bin/bash # drops you into new container as root
    # https://docs.docker.com/installation/ubuntulinux/#ubuntu-trusty-1404-lts-64-bit

    # other great tips: http://www.centurylinklabs.com/15-quick-docker-tips/
    # fix fig / docker config: https://gist.github.com/RuslanHamidullin/94d95328a7360d843e52
    # fix fig / docker config: https://gist.github.com/RuslanHamidullin/94d95328a7360d843e52
  9. garystafford revised this gist Nov 10, 2015. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions helpful-docker-commands.sh
    Original file line number Diff line number Diff line change
    @@ -11,6 +11,7 @@ docker rm $(sudo docker ps --before="container_id_here" -q) # can also filter
    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
  10. garystafford revised this gist Jun 14, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion helpful-docker-commands.sh
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ docker rm $(docker ps -a -q) # remove ALL containers
    docker rm $(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 "vehicle" /bin/bash # Go to container command line
    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)

    ### IMAGES ###
  11. garystafford revised this gist Jun 14, 2015. 1 changed file with 30 additions and 42 deletions.
    72 changes: 30 additions & 42 deletions helpful-docker-commands.sh
    Original file line number Diff line number Diff line change
    @@ -2,55 +2,43 @@
    # 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
    ### CONTAINERS ###
    docker ps -a # list all containers
    docker stop $(docker ps -a -q) #stop ALL containers
    docker rm $(docker ps -a -q) # remove ALL containers
    docker rm $(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 "vehicle" /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)

    ### IMAGES ###
    # list images and containers
    docker images # all images
    docker ps -a # all containers

    docker images | grep <search_term>

    # start and attach to container
    docker start <container>
    docker attach <container>

    # stop and remove container
    docker stop <container>
    docker rm <container>

    #stop and remove ALL containers
    docker stop $(docker ps -a -q)
    docker rm $(docker ps -a -q)

    docker rm $(sudo docker ps --before="<container>" -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)

    docker images | grep "search_term_here"
    # remove image(s) (must remove associated containers first)
    docker rmi <image>
    docker rmi $(docker images | grep <container>)
    docker rmi $(docker images | grep "<search_term>") # ie. "2 days ago"

    # remove all <none> images
    docker rmi $(docker images | grep "^<none>" | awk "{print $3}")
    docker rmi image_id_here # remove image(s)
    docker rmi $(docker images -q) # remove ALL images!!!
    docker rmi $(docker images | grep "^<none>" | awk "{print $3}") # remove all <none> images
    docker rmi $(docker images | grep "search_term_here") # ie. "2 days ago"

    # remove ALL images!!!
    docker rmi $(docker images -q)

    # to only stop exited containers and delete only non-tagged images
    ### BOTH IMAGES AND CONTAINERS ###
    docker images && docker ps -a
    # stop and remove containers and associated images with common grep search term
    docker ps -a --no-trunc | grep "search_term_here" | awk "{print $1}" | xargs -r --no-run-if-empty docker stop && \
    docker ps -a --no-trunc | grep "search_term_here" | awk "{print $1}" | xargs -r --no-run-if-empty docker rm && \
    docker images --no-trunc | grep "search_term_here" | awk "{print $3}" | xargs -r --no-run-if-empty docker rmi
    # stops only 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 "<search_term>" | awk "{print $1}" | xargs -r --no-run-if-empty docker stop && \
    docker ps -a --no-trunc | grep "<search_term>" | awk "{print $1}" | xargs -r --no-run-if-empty docker rm && \
    docker images --no-trunc | grep "<search_term>" | awk "{print $3}" | xargs -r --no-run-if-empty docker rmi
    ### NEW IMAGES/CONTAINERS ###
    # 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

    ### OTHER ###
    # install docker first using directions for installing latest version
    # https://docs.docker.com/installation/ubuntulinux/#ubuntu-trusty-1404-lts-64-bit

    # other great tips: http://www.centurylinklabs.com/15-quick-docker-tips/
    # fix fig / docker config: https://gist.github.com/RuslanHamidullin/94d95328a7360d843e52
  12. garystafford revised this gist Jun 14, 2015. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions helpful-docker-commands.sh
    Original file line number Diff line number Diff line change
    @@ -12,6 +12,7 @@ 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 <search_term>

    # start and attach to container
    @@ -35,7 +36,7 @@ docker rm -f $(docker ps -a -q)
    # remove image(s) (must remove associated containers first)
    docker rmi <image>
    docker rmi $(docker images | grep <container>)
    docker rmi $(docker images | grep "<search_term") # ie. "2 days ago"
    docker rmi $(docker images | grep "<search_term>") # ie. "2 days ago"

    # remove all <none> images
    docker rmi $(docker images | grep "^<none>" | awk "{print $3}")
    @@ -46,11 +47,10 @@ 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 container and associated image with common grepped values
    docker ps -a --no-trunc | grep 'virtual-vehicle' | awk '{print $1}' | xargs -r --no-run-if-empty docker stop && \
    docker ps -a --no-trunc | grep 'virtual-vehicle' | awk '{print $1}' | xargs -r --no-run-if-empty docker rm && \
    docker images --no-trunc | grep 'virtual-vehicle' | awk '{print $3}' | xargs -r --no-run-if-empty docker rmi

    # stop and remove containers and associated images with common grep search term
    docker ps -a --no-trunc | grep "<search_term>" | awk "{print $1}" | xargs -r --no-run-if-empty docker stop && \
    docker ps -a --no-trunc | grep "<search_term>" | awk "{print $1}" | xargs -r --no-run-if-empty docker rm && \
    docker images --no-trunc | grep "<search_term>" | 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
  13. garystafford revised this gist Jun 11, 2015. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions helpful-docker-commands.sh
    Original file line number Diff line number Diff line change
    @@ -47,9 +47,10 @@ docker rmi $(docker images -q)
    docker ps --filter 'status=Exited' -a | xargs docker stop docker images --filter "dangling=true" -q | xargs docker rmi

    # stop and remove container and associated image with common grepped values
    docker ps -a | grep '{tag-goes-here}' | awk '{print $1}' | xargs --no-run-if-empty docker stop && \
    docker ps -a | grep '{tag-goes-here}' | awk '{print $1}' | xargs --no-run-if-empty docker rm && \
    docker images -a | grep '{tag-goes-here}' | awk '{print $1}' | xargs --no-run-if-empty docker rmi
    docker ps -a --no-trunc | grep 'virtual-vehicle' | awk '{print $1}' | xargs -r --no-run-if-empty docker stop && \
    docker ps -a --no-trunc | grep 'virtual-vehicle' | awk '{print $1}' | xargs -r --no-run-if-empty docker rm && \
    docker images --no-trunc | grep 'virtual-vehicle' | 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
  14. garystafford revised this gist Jun 10, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion helpful-docker-commands.sh
    Original file line number Diff line number Diff line change
    @@ -46,7 +46,7 @@ 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 container and associated image with common grepped value
    # stop and remove container and associated image with common grepped values
    docker ps -a | grep '{tag-goes-here}' | awk '{print $1}' | xargs --no-run-if-empty docker stop && \
    docker ps -a | grep '{tag-goes-here}' | awk '{print $1}' | xargs --no-run-if-empty docker rm && \
    docker images -a | grep '{tag-goes-here}' | awk '{print $1}' | xargs --no-run-if-empty docker rmi
  15. garystafford revised this gist Jun 10, 2015. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions helpful-docker-commands.sh
    Original file line number Diff line number Diff line change
    @@ -46,5 +46,10 @@ 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 container and associated image with common grepped value
    docker ps -a | grep '{tag-goes-here}' | awk '{print $1}' | xargs --no-run-if-empty docker stop && \
    docker ps -a | grep '{tag-goes-here}' | awk '{print $1}' | xargs --no-run-if-empty docker rm && \
    docker images -a | grep '{tag-goes-here}' | awk '{print $1}' | xargs --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
  16. garystafford revised this gist Feb 16, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion helpful-docker-commands.sh
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    ###############################################################################
    # Helpful Docker commands to create, start, and stop containers
    # Helpful Docker commands and code snippets
    ###############################################################################

    # install docker first using directions for installing latest version
  17. garystafford revised this gist Nov 26, 2014. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions helpful-docker-commands.sh
    Original file line number Diff line number Diff line change
    @@ -43,5 +43,8 @@ docker rmi $(docker images | grep "^<none>" | 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

    # other great tips: http://www.centurylinklabs.com/15-quick-docker-tips/
    # fix fig / docker config: https://gist.github.com/RuslanHamidullin/94d95328a7360d843e52
  18. garystafford revised this gist Nov 26, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions helpful-docker-commands.sh
    Original file line number Diff line number Diff line change
    @@ -29,6 +29,7 @@ docker rm $(docker ps -a -q)
    docker rm $(sudo docker ps --before="<container>" -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)
  19. garystafford revised this gist Nov 26, 2014. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions helpful-docker-commands.sh
    Original file line number Diff line number Diff line change
    @@ -25,6 +25,7 @@ docker rm <container>
    #stop and remove ALL containers
    docker stop $(docker ps -a -q)
    docker rm $(docker ps -a -q)

    docker rm $(sudo docker ps --before="<container>" -q) # can also filter

    # Remove all in one command with --force
    @@ -35,6 +36,9 @@ docker rmi <image>
    docker rmi $(docker images | grep <container>)
    docker rmi $(docker images | grep "<search_term") # ie. "2 days ago"

    # remove all <none> images
    docker rmi $(docker images | grep "^<none>" | awk "{print $3}")

    # remove ALL images!!!
    docker rmi $(docker images -q)

  20. garystafford revised this gist Nov 26, 2014. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions helpful-docker-commands.sh
    Original file line number Diff line number Diff line change
    @@ -27,10 +27,16 @@ docker stop $(docker ps -a -q)
    docker rm $(docker ps -a -q)
    docker rm $(sudo docker ps --before="<container>" -q) # can also filter

    # Remove all in one command with --force
    docker rm -f $(docker ps -a -q)

    # remove image(s) (must remove associated containers first)
    docker rmi <image>
    docker rmi $(docker images | grep <container>)
    docker rmi $(docker images | grep "<search_term") # ie. "2 days ago"

    # remove ALL images!!!
    docker rmi $(docker images -q)

    # other great tips: http://www.centurylinklabs.com/15-quick-docker-tips/
    # fix fig / docker config: https://gist.github.com/RuslanHamidullin/94d95328a7360d843e52
  21. garystafford created this gist Nov 22, 2014.
    36 changes: 36 additions & 0 deletions helpful-docker-commands.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    ###############################################################################
    # Helpful Docker commands to create, start, and stop containers
    ###############################################################################

    # 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 <search_term>

    # start and attach to container
    docker start <container>
    docker attach <container>

    # stop and remove container
    docker stop <container>
    docker rm <container>

    #stop and remove ALL containers
    docker stop $(docker ps -a -q)
    docker rm $(docker ps -a -q)
    docker rm $(sudo docker ps --before="<container>" -q) # can also filter

    # remove image(s) (must remove associated containers first)
    docker rmi <image>
    docker rmi $(docker images | grep <container>)
    docker rmi $(docker images | grep "<search_term") # ie. "2 days ago"

    # other great tips: http://www.centurylinklabs.com/15-quick-docker-tips/
    # fix fig / docker config: https://gist.github.com/RuslanHamidullin/94d95328a7360d843e52