Day 20 - Docker Cheat-Sheet

Day 20 - Docker Cheat-Sheet

ยท

3 min read

Introduction

Welcome DevOps enthusiasts and learners. In this blog we're gonna get our hands dirty and sum up all the concepts that we have learnt in the past few days about docker. We are going to create our very own cheat sheet for our future revisions and references.

From Day 16 to Day 19, we're gonna sum up every concepts and create a comprehensive cheat-sheet for ourselves. So without delaying, let's just begin.

Commands

Here's the cheat-sheet of Docker commands according to the tasks they perform:

  1. To pull an Image from Docker Hub:

     docker pull <image_name>:version
    
  2. To run a container:

     docker run <image_name>
    
  3. Flags for running a container:

     -d: to run in background
    
  4. To inspect a container:

     docker inspect <container_name>
    
  5. List of Running Containers:

     docker ps
    
  6. List all the containers (Running or stopped):

     docker ps -a
    
  7. List of images on the system:

     docker images
    
  8. Docker Port Mapping:

     docker run -p host_port:container_port <image_name>
    
  9. Map a volume:

     docker run -v HOSTDIR:TARGETDIR <image_name>
    
  10. To assign a name to the container while running:

    docker run --name Name <Image_name>
    
  11. To stop a container:

    docker stop <container_name_or_id>
    
  12. To start a stopped container:

    docker start <container_name_or_id>
    
  13. To kill a container:

    docker kill <container_name_or_id>
    
  14. To remove a container:

    docker rm <container_name_or_id>
    
  15. Delete a running container:

    docker rm -f <container_name_or_id>
    
  16. Copy files from container to host:

    docker cp <container_name>:<file_name> <file_name>
    
  17. Copy files from host to container:

    docker cp <file_name> <container_name>:<file_source>
    
  18. Run a command inside a running container:

    docker exec -it <container_name> <name_of_shell>
    
  19. Create an image out of a container:

    docker commit <container_name_or_id>
    
  20. To delete an image:

    docker rmi <image_name>
    
  21. To delete all images:

    docker image prune -a
    
  22. To remove unused resources (container, Images, etc.):

    docker system prune
    
  23. Build an image from Dockerfile:

    docker build DOCKERFILE
    
  24. Build and tag the image at the same time:

    docker build -t <Name> <DockerFile> .
    
  25. Tag an image:

    docker tag <image_id_or_name> <new_tag>
    
  26. To connect with your Docker Hub account:

    docker login <registry_url>/<repository_name>:<tag>
    
  27. Push an image to Docker Hub:

    docker push <registry_url>/<repository_name>:<tag>
    
  28. See Logs of container:

    docker logs <Container_name_or_id>
    
  29. See Modified files in a container:

    docker diff <Container_name>
    
  30. See the stats of the running container:

    docker stats
    
  31. Delete Stopped containers:

    docker containers prune
    
  32. Rename a container:

    docker rename <Old_name> <New_Name>
    
  33. Save an image to a tar file:

    docker save <Image> > FILE.tar
    
  34. Load an image from a tar file:

    docker load -i FILE.tar
    

Conclusion

In this cheat sheet, we covered the extensive set of Docker commands needed to manage containers, images, volumes, and more. Whether you're a beginner Docker installer or an experienced user looking to simplify your workflow, these commands provide intuitive tutorials for tasks ranging from running containers to images managing types to connectivity and troubleshooting.

By getting these commands right, you can effectively deploy, monitor, and maintain them, empowering you to use the full power of Docker in your development and deployment planning. With the knowledge in this cheat sheet, you're ready to enter the world of containerization with confidence.

I hope this blog added some Value to your learning. Do curate and share your own chat-sheet on LinkedIn and don't forget to tag me.

Ending this with a quote

Every great developer you know got there by solving problems they were unqualified to solve until they actually did it. - Patrick McKenzie

Happy Learning.

Did you find this article valuable?

Support DevOps with Aakash by becoming a sponsor. Any amount is appreciated!

ย