The MOST EVER usefullest Docker commands (as determined by some guy on the internet)

Full article

After taking my first look at Docker and then playing around with building images, I've now progressed into other proprietary work stuff, so... won't be sharing that on here. I like having a job.

That being said, I'll just make note of any useful commands I come across this week. As much for me as you!


  • Create an image from a Dockerfile: docker build .
  • Create a container from an image (run in bkgd): docker run -d <image hash>
  • Interact with running container: docker exec -it <container hash> bash
  • Create a container and interact with it: docker run -it <image hash>

The exec command is great. It allows you execute a command inside a running, such as using some tool only available in the container to export some settings, which you can dump in a directory that's being shared with the -v flag, so that you can import it into future containers. Handy stuff.


  • View images: docker images
  • View containers: docker ps or docker container ls
  • View all containers (including stopped ones): docker ps -a


(Layers of) images are the blueprint for the application you'd like to run, while containers are an instance of an image. You can spin up multiple containers for a given image, and each container is separate.


  • Stop all containers: docker stop $(docker ps -a -q)
  • Remove stopped containers: docker rm $(docker ps -a -q)
  • Kill all containers (even running ones): docker rm -f $(docker ps -a -q)


  • Remove image (unless a container or another image exists that's based off it): docker rmi $(docker images -q)
  • Force removal: docker rmi -f $(docker images -q)


Grant Winney

I write when I've got something to share - a personal project, a solution to a difficult problem, or just an idea. We learn by doing and sharing. We've all got something to contribute.

Comments / Reactions