How To See Docker Image Contents?
Last Updated :
01 Mar, 2024
In the evolving world of containerization, Docker has emerged as a tool for packaging and deploying applications. While creating and sharing Docker images has streamlined the development and deployment process.
Contents of a Docker image are important for troubleshooting, optimizing, and ensuring security in your containerized applications. This article guides on how to inspect the contents of a docker image.
Inspecting the docker image directly is not possible but we can inspect docker containers that are built on the image itself.
Methods to see docker image contents
There are two methods by which we can see the contents of the docker image. You can view the contents of the image using the container.
1. Docker Desktop
Docker Desktop is a GUI to manage images, containers, and volumes.
- Build your docker image.
- Run your container.
- Open the containers section from the docker desktop.
- Open your container (practical_banach here).
.png)
- Open the Files tabs from the top menu.
.png)
From this, we can view all the files and sub-directories in a docker container.
2. Using CLI
The command line interface allows you to view files in the shell using commands.
- Build a docker image.
- Run docker container.
Run docker container using following syntax.
docker run <image-name>
Use '-p' to expose your port number.
Use '--detach' to run your container in background. This will allow you to perform another operations from same terminal.
.png)
Inspect Docker Image
Using the following command you can view detailed information about an image, including its layers and filesystem changes.
docker inspect <image-name>
.png)
Save & Extract Docker Image
You can save a docker image, use the docker save command followed by the name of the image and tar file name separated by '>'.
docker save image-name > file-name.tar
You can extract a docker image, use the docker import command followed by the name of the tar archive and image name.
docker import file-name.tar image-name
After successful execution of extraction the sha will be visible.
.png)
i. Docker Execute
docker exec allows you to execute commands within an already deployed container, or outside of the container.
docker exec <container_name> ls /
docker exec <container_name> ls <path>
.png)
This command will list all the files in the present directory.You can change the file path to list files in the given directory given in the command.
ii. Create Text file
docker export allows you to export and create files on your local system.
docker export my-container | tar t > my-container-files.txt
You can replace my container name with your container name.
Replace my-container-files name to change the output text file name.
.png)
Conclusion
In this article, we explored CLI commands and docker desktop to inspect the image using containers. We also exported the contents of the image in a text file using the docker export command. Choosing right method is very important you can use docker desktop which is GUI to view and maintain images and container very easily. But GUI can be very helpful for development purpose. If someone wants to share and collaborate image contents one can extract data into text file using CLI and share it.
Similar Reads
How to Create Docker Image?
Docker is a powerful containerization tool that enables developers to package their applications and their dependencies into a single unit called Docker image. The Docker image offers seamless deployment, scalability, and portability. In this article, I will make sure that you understand what is doc
12 min read
How to Install Docker on CentOS?
Quick Preview to Install Docker on CentOS:Installation of Docker on CentOS:Open CentOS Terminal.Execute the command yum update in the Root Menu.Run the command yum install -y yum-utils device-mapper-persistent-data lvm2.Execute the command yum-config-manager --add-repo https://download.docker.com/li
4 min read
How to Remove Docker Containers
Docker is a platform that provides a set of PaaS (Platform as a Service) products that help developers containerize applications, allowing them to run consistently across various supported environments. The core component of Docker is Docker Engine which consists of: Docker Daemon: The process respo
2 min read
How To Rebuild the Docker Image ?
Docker has forever changed the way developers build, package, and deploy applications. It permits them to run applications in isolated environments that are mostly named containers, at the core of Docker is an image: a lightweight, stand-alone, and executable package that includes everything needed
6 min read
How To Optimize Docker Image ?
Docker images are small executable packages that can be used to run a program along with its libraries, dependencies, code, and runtime. Docker images form the basis of Docker containers, which allow software to be deployed continuously across several environments. We will be talking more about Dock
10 min read
How To Comment In Dockerfile?
The purpose of comments in a Dockerfile is to both clarify and improve the readability of the instructions. It can also be used to stop execution when testing other code. The comments are meant to serve as a source of code line information. Comments are a frequent way for programmers to document the
3 min read
How to Setup Jenkins in Docker Container?
Setting up of Jenkins in a docker container provides the facility of streamlining the CI/CD with scalability and consistency. It also helps for attaching the worker nodes as slaves and run the build jobs over their. In this article, we will guide you through the process of deploying jenkins in a Doc
6 min read
How to Push a Container Image to a Docker Repository?
In this article we will look into how you can push a container image to a Docker Repository. We're going to use Docker Hub as a container registry, that we're going to push our Docker image to. Follow the below steps to push container Image to Docker repository:Step 1: Create a Docker Account The f
3 min read
How To Push A Docker Image To Amazon ECR?
We go over how to submit a Docker image to the Amazon Elastic Container Registry (ECR) in this tutorial. By offering a safe, scalable registry for storing and distributing Docker images inside the AWS ecosystem, Amazon ECR streamlines container management. To upload and maintain your containerized a
4 min read
What Is Docker Trust Content ?
When we are using Docker images, we must think about whether the image we are using is trustworthy or not, because trust is a central concern in every field. especially when we download external resources from our local system. In this scenario, Docker comes up with a special security feature called
8 min read