Skip to content

Instantly share code, notes, and snippets.

@je2ryw
Forked from garystafford/helpful-docker-commands.sh
Created February 23, 2020 22:52
Show Gist options
  • Save je2ryw/5e10906960c697d55343f602d7a3b5d0 to your computer and use it in GitHub Desktop.
Save je2ryw/5e10906960c697d55343f602d7a3b5d0 to your computer and use it in GitHub Desktop.
My list of helpful docker commands
###############################################################################
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment