Day20 of #90daysofdevops | Docker cheat sheet

Day20 of #90daysofdevops | Docker cheat sheet

ยท

2 min read

So far we have learned everything about docker in previous blogs where we used several commands.

Today's blog is the one-stop solution for all the commands related to docker.

Docker Cheat Sheet

Basics:

  • Pull an image from Docker Hub:

      docker pull image_name:tag
    
  • List downloaded images:

      docker images
    
  • Run a container from an image:

      docker run [options] image_name:tag
    
  • List running containers:

      docker ps
    
  • List all containers (including stopped):

      docker ps -a
    
  • Start a stopped container:

      docker start container_id_or_name
    
  • Stop a running container gracefully:

      docker stop container_id_or_name
    
  • Forcefully stop a running container:

      docker kill container_id_or_name
    
  • Remove a container:

      docker rm container_id_or_name
    
  • Remove an image:

      docker rmi image_id_or_name
    

Advanced:

  • Run a container with a custom name:

      docker run --name custom_container_name image_name:tag
    
  • Run a container in detached/background mode:

      docker run -d image_name:tag
    
  • Map a host port to a container port:

      docker run -p host_port:container_port image_name:tag
    
  • Mount a host directory into a container:

      docker run -v /host/path:/container/path image_name:tag
    
  • View logs of a container:

      docker logs container_id_or_name
    
  • Execute a command inside a running container:

      docker exec -it container_id_or_name command
    
  • Build an image from a Dockerfile:

      docker build -t image_name:tag /path/to/Dockerfile_directory
    
  • Push an image to Docker Hub (after tagging):

      docker push image_name:tag
    
  • Clean up unused resources (containers, images, volumes, networks):

      docker system prune
    
  • Inspect container or image details:

      docker inspect container_or_image_id_or_name
    
  • Check Docker version:

      docker --version
    
  • Compose and manage multi-container applications with Docker Compose.

Remember to replace the placeholders image_name, tag, container_id_or_name, host_port, container_port, etc., with your specific values.

Also, you can follow this image:

This cheat sheet covers some of the basic and advanced Docker commands. Docker is a powerful tool with many features, and there's much more to explore. Happy containerization!

Thanks for reading the blog & do share them with someone in need :)

Please share your views and suggestions, they are always welcome.

See you then in the next blog.

Happy learning :)

ย