DEV Community

Cover image for How to inspect the docker image?
Sarvesh Mishra
Sarvesh Mishra

Posted on • Originally published at sarvesh.xyz

How to inspect the docker image?

When it comes to Microservice architecture, the docker image is like the soul of the system. It is essential to understand the purpose of a docker image and what it contains so that you can use the right image for your needs. Whether you're browsing Docker Hub or working with legacy code, you'll encounter various types of docker images with different sizes. In my recent migration project, I had to inspect docker images carefully to ensure a smooth migration without any errors. But how do you know what's inside a docker image? Let's take a deep dive into the world of docker images...

  1. Pull the Docker Image: If you haven't already, you need to pull the Docker image you want to inspect. You can do this using the docker pull command. If you are new to docker you can read basics of the docker here and basic docker commands here For example:
   docker pull <image_name>:<tag>
Enter fullscreen mode Exit fullscreen mode

Replace <image_name> with the name of the Docker image and <tag> with the specific version or tag you want to pull.

  1. Create a Temporary Container: You can create a temporary Docker container from the image you just pulled. This container will be used for inspection. Use the docker run command:
   docker run -it --name temp_container <image_name>:<tag> /bin/bash
Enter fullscreen mode Exit fullscreen mode

Replace <image_name> and <tag> with the same image and tag you pulled earlier. The --name option assigns a name to the container, and /bin/bash starts an interactive shell within the container.

  1. Inspect the Container: Now that you have a shell inside the container, you can use standard Linux commands to inspect its contents. For example:
  • To list installed packages and their versions (on Debian-based systems, like Ubuntu), you can use:
   dpkg -l
Enter fullscreen mode Exit fullscreen mode
  • To list installed packages and their versions (on Red Hat-based systems, like CentOS), you can use:
   rpm -qa
Enter fullscreen mode Exit fullscreen mode
  • To examine the file system, navigate to the root directory and use standard file system commands like ls, cd, and cat to inspect files and directories.
  1. Exit the Container: Once you've finished inspecting the container, you can exit the interactive shell:
   exit
Enter fullscreen mode Exit fullscreen mode
  1. Cleanup: To remove the temporary container, you can use the docker rm command:
   docker rm temp_container
Enter fullscreen mode Exit fullscreen mode

After examining the contents of the Docker image, which includes package versions and other details, it's important to note that the commands for inspecting packages may differ based on the Linux distribution used in the Docker image (for example, Debian, Ubuntu, CentOS, etc.). To ensure accuracy, use the appropriate package manager (dpkg for Debian-based or rpm for Red Hat-based) and modify the commands accordingly.

Happy Dockerizing! 🐋 See you in next post. Don't forget to comment your thoughts for this post. Share knowledge with others...

Top comments (0)