More Essential Docker Commands 🚀 Part 2

More Essential Docker Commands 🚀 Part 2

< How Do We get the Number Of Containers Running, Paused, and Stopped? >

Ans:

  • docker ps -q | wc -l

== Used to list all the Running state containers

  • docker ps -aq -f "status=paused" | wc -l

== Used to list all containers in Paused state

  • docker ps -aq -f "status=exited" | wc -l

== Used to list all containers in Stopped state


Article content


  • -q: Show only container IDs.

  • -f: Filter containers based on the specified condition (there I have used case, status=exited).
  • -a: List all containers - not just the running ones


< What Command Should We Run to Export a Docker Image as an Archive? >

Ans:

docker save -o <output_file_name>.tar <image_name>

Description: This command saves a Docker image to a tar archive file.

Example: docker save -o my_image.tar my_image

Use Case: Perfect for backing up Docker images or transferring them between different systems or environments.

  • -o : This option is used to specify the file name and location for saving Docker image.

Here, This command saves the Docker image called my_image into a file named my_image.tar.


Thank you so much for reading along! 😊 I’m always open to your suggestions and feedback. Let’s continue learning and growing together. 🌟 See you next time! 👋


To view or add a comment, sign in

Others also viewed

Explore topics