- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to find Docker container processes?
Introduction
Docker is a powerful tool that allows developers to build, ship, and run applications inside containers. Containers are small, independent executable packages that contain all the components - code, libraries, dependencies, and runtime - that an application requires to function. One of the key features of Docker is the ability to manage and monitor the processes running inside containers.
In this article, we will explore how to find Docker container processes and how to use different methods to view and manage them.
Prerequisites
You will need Docker installed on your computer in order to follow along with this guide. By using the following command, you may determine whether Docker is installed −
$ docker --version
If Docker is not installed, you can follow the official Docker installation guide for your operating system.
Methods
There are several methods to find the Docker container processes. We will be talking about some of these here −
Docker inspect command
Docker top command
Docker exec command
Let us discuss each of these methods in detail along with examples.
Docker inspect command
We may obtain comprehensive details about a specific container, including its processes, using the Docker inspect command. This can help with troubleshooting or with gaining more insight into how a container is operating.
Syntax
We use the command that follows to utilize the docker inspect −
$ docker inspect <container-name>
Example
Step 1 − Navigate to your project directory in your code editor that has the Docker container for which you need to find the container processes.
For using your terminal to navigate, use the following command −
$ cd path-of-the-directory
Step 2 − In the terminal, run the following command −
$ docker inspect docker-apps
This will print comprehensive details about the container "my-container," along with the processes that are currently running inside of it.
Output
[ { "Id": "sha256:eb6dda32a60d823a3816d88ed4b9d79c8fadca744d1ee1556231c00f8759f89e", "RepoTags": [ "docker-apps:latest" ], "RepoDigests": [], "Parent": "", "Comment": "buildkit.dockerfile.v0", "Created": "2023-01-08T05:13:17.063330293Z", "Container": "", "ContainerConfig": { "Hostname": "", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": null, "Cmd": null, "Image": "", "Volumes": null, "WorkingDir": "", "Entrypoint": null, "OnBuild": null, "Labels": null }, "DockerVersion": "", "Author": "", "Config": { "Hostname": "", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "NODE_VERSION=19.4.0", "YARN_VERSION=1.22.19" ], "Cmd": [ "/bin/sh", "-c", "node app.js" ], "ArgsEscaped": true, "Image": "", "Volumes": null, "WorkingDir": "/app", "Entrypoint": [ "docker-entrypoint.sh" ], "OnBuild": null, "Labels": null }, "Architecture": "amd64", "Os": "linux", "Size": 176079128, "VirtualSize": 176079128, "GraphDriver": { "Data": { "LowerDir": "/var/lib/docker/overlay2/8p8o9wm9g6dwlhibzwd14zzsg/diff:/var/lib/docker/overlay2/9b834a59db8eb73cfea182889e02167519d51b77275278d12b0f0836ff9cb591/diff:/var/lib/docker/overlay2/9b546e9fd0a50f20bddd71bb4a8156e2fcbf1c52dc94d3c312c7c962320a10ad/diff:/var/lib/docker/overlay2/a76e906cbf39ed57b5b973cf95d43b379713ced3bf29de44a628894f3036e599/diff:/var/lib/docker/overlay2/e4c1f1bb76c66c5d1781a775c8a2ca9338065ea0b398aeaed4230a00a15d2952/diff", "MergedDir": "/var/lib/docker/overlay2/x8mn6648vzpbkai1h0fsqi7cz/merged", "UpperDir": "/var/lib/docker/overlay2/x8mn6648vzpbkai1h0fsqi7cz/diff", "WorkDir": "/var/lib/docker/overlay2/x8mn6648vzpbkai1h0fsqi7cz/work" }, "Name": "overlay2" }, "RootFS": { "Type": "layers", "Layers": [ "sha256:ded7a220bb058e28ee3254fbba04ca90b679070424424761a53a043b93b612bf", "sha256:9a6a030b65c4b6ac82eacf5ad6c84cbf66889e7f242b8eb4ff5645e58c24ab54", "sha256:72133ba0a087ab86a8688dec714d4641ed1b3d595d4293bf1009d4f6cde56ce3", "sha256:ed1deaa8b02f03679b53d4be39743add0c6315f88ae2586f90d54b3dcca9003d", "sha256:f8684c5845f4a6611e51ecdc18d83c50cd42dbf7dfbb119caf8909b326da183e", "sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef" ] }, "Metadata": { "LastTagTime": "2023-01-08T05:13:17.19313535Z" } } ]
Docker top command
Users can view the processes running in a Docker container in real time by using the docker top command. This command is helpful for diagnosing and debugging problems as well as quickly determining which programs are utilizing resources.
Syntax
The following command will help you utilize it −
$ docker top <container-name>
Example
Step 1 − Navigate to your project directory in your code editor that has the Docker container for which you need to find the container processes.
Step 2 − In the terminal, run the following command −
$ docker top my-docker
This will list all the processes running inside the container "my-container".
Output
UID PID PPID C STIME TTY TIME CMD root 2534 2379 0 10:35 ? 00:00:00 /sbin/tini -- /usr/local/bin/jenkins.sh jenkins 2535 2534 0 10:35 ? 00:00:00 /bin/tini -- /usr/local/bin/jenkins.sh jenkins 2612 2535 0 10:35 ? 00:00:00 /usr/local/openjdk-8/bin/java -Djenkins.install.runSetupWizard=false -Djava.awt.headless=true -jar /usr/local/jenkins/jenkins.war --logfile=/var/jenkins_home/jenkins.log --webroot=/var/cache/jenkins/war --httpPort=8080
The Jenkins-running container in this example was given the docker top command, and the result lists the process IDs and names for those processes.
Docker exec command
Users can execute a command inside an active Docker container by using the docker exec command. This command can be used to interact with processes inside a container as well as to inspect the state of the container.
Syntax
The following command will help you to utilize it −
$ docker exec <container-name> <command>
Example
Step 1 − Navigate to your project directory in your code editor that has the Docker container for which you need to find the container processes.
Step 2 − In the terminal, run the following command −
$ docker exec my-container ps aux
The container "my-container" will execute the "ps aux" command, which will list every process running within it.
Output
$ docker exec docker-apps ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.0 32784 4360 ? Ss 06:05 0:00 /bin/bash root 37 0.0 0.0 16780 3000 ? R+ 06:05 0:00 ps aux
The processes operating inside the container with the ID docker-apps are displayed in this output. The ps aux command displays a list of all the processes currently active in the container, together with information about each process's user, PID, CPU, RAM, virtual memory, resident set size, terminal, status, start time, and command.
Conclusion
In this article, we explored how to find Docker container processes and how to use different methods to view and manage them. The top command allows you to view the running processes inside a container, the exec command allows you to run a command inside a running container, and the inspect command allows you to view detailed information about a container, including its processes. By using these methods, you can effectively manage and monitor the processes running inside your Docker containers.
- Related Articles
- How to get a Docker Container IP address?
- How to backup and restore a Docker Container?
- How to run a command inside Docker Container?
- How to rebuild Docker container on file changes?
- How to copy files from host to Docker container?
- How to fix Ctrl+C inside a Docker container?
- Copying files from Docker container to Host
- Creating a MySQL Docker Container
- How could I bind Docker container to specific external interface?
- How to Debug a Node.js app in a Docker Container?
- How to upgrade docker container with previous network and volumes?
- How many CPUs does a docker container use?
- How to pass command line arguments to a python Docker container?
- Copy Files from Docker Container to Local Machine
- How to execute a script when I terminate a Docker container?
