How to inspect the docker image?

Sarvesh Mishra
2 min readSep 18, 2023

--

Docker Illustration

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 the basics of the docker [here] and basic docker commands [here] For example:

docker pull <image_name>:<tag>

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

2. 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

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.

3. 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

- To list installed packages and their versions (on Red Hat-based systems, like CentOS), you can use:

rpm -qa

- 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.

4. Exit the Container: Once you’ve finished inspecting the container, you can exit the interactive shell:

exit

5. Cleanup: To remove the temporary container, you can use the `docker rm` command:

docker rm temp_container

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 the next post. Don’t forget to comment your thoughts on this post. Share knowledge with others…

Originally published at https://sarvesh.xyz.

--

--

Sarvesh Mishra

Sarvesh is a Full Stack Developer specializing in the Backend with Software Architecture and Machine Learning experience at carwale.com