Commonly Used Docker Commands Cheat Sheet

AWS By Jul 15, 2023 No Comments

Cheat sheet for some commonly used Docker commands:

  1. docker run <image>: Starts a new container from the specified image.
  2. docker ps: Lists running containers.
  3. docker ps -a: Lists all containers (including those that are stopped).
  4. docker pull <image>: Pulls the specified image from DockerHub.
  5. docker stop <container_id>: Stops a running container.
  6. docker rm <container_id>: Removes a container. The container must be stopped first.
  7. docker images: Lists all images on your local system.
  8. docker rmi <image_id>: Removes an image.
  9. docker start <container_id>: Starts a stopped container.
  10. docker inspect <container_id>: Shows detailed information about a container.
  11. docker logs <container_id>: Shows the logs of a container.
  12. docker exec -it <container_id> /bin/bash: Opens a new shell inside an already running container.

Also Read: Powerful kubectl Commands for Kubernetes | Manage Resources, Interact with Clusters, Debug & More

  1. docker build -t <image_name> .: Builds a Docker image from a Dockerfile in the current directory.
  2. docker run -d <image>: Runs a container in detached mode (in the background).
  3. docker run -p <host_port>:<container_port> <image>: Starts a new container and forwards the specified port from the container to the host.
  4. docker run -v <host_dir>:<container_dir> <image>: Starts a new container and mounts the specified host directory into the container.
  5. docker commit <container_id> <new_image_name>: Creates a new image from a container's changes.
  6. docker login: Login to the DockerHub.
  7. docker push <username/image_name>: Pushes an image to DockerHub.
  8. docker tag <image_id> <username/image_name>: Tags an image with a new name.

This is not an exhaustive list of all Docker commands. There are many more commands and options available in Docker. Please refer to the Docker documentation for more detailed information:

Also Read: How to Set Up an EKS Cluster with eksctl command line


I'm Abhay Singh, an Architect with 9 Years of It experience. AWS Certified Solutions Architect.

No Comments

Leave a comment

Your email address will not be published. Required fields are marked *