Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get services and its status inside the docker containers?

Tags:

docker

I'm having docker containers in Linux server, I need know how to get details of applications, services and its status inside the containers. Which command do I need to execute to get those details.

For example:

A container contains tomcat server. I need to get the details of tomcat server and its status(whether the service is running or not).

I don't know is there any command available to get those details.

like image 290
Kavi Chinna Avatar asked Oct 24 '25 02:10

Kavi Chinna


2 Answers

you can use the docker exec command to execute any command you need inside the container.

For instance, to list all running processes inside a container:

docker exec <my container> ps aux

or to display the content of a file

docker exec <my container> cat /etc/resolv.conf

Those commands will be executed with the user defined in your image. You can override it with the -u option:

docker exec -u root <my container> ls -l

If you need to run multiple commands, or use environment variables that exists within the container, use the following trick:

docker exec <my container> sh -c 'echo ~; echo "PATH: $PATH"'
like image 81
Thomasleveil Avatar answered Oct 26 '25 18:10

Thomasleveil


LIST all containers:

docker stats $(docker ps|grep -v "NAMES"|awk '{ print $NF }'|tr "\n" " ") --no-stream

LIST containers with memory usage more than 99%:

docker stats $(docker ps|grep -v "NAMES"|awk '{ print $NF }'|tr "\n" " ") --no-stream | sort -k 8n | awk '(NR>1) && ($8 > 99 ) '

like image 36
Jay T Avatar answered Oct 26 '25 18:10

Jay T



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!