How To Get Information About Running Containers, Images In Docker?
Docker provides different tools to monitor the containers. In a busy environment there will be a lot of images and containers hard to remember. We can use information sub-commands provided by docker to get more detailed port, disk, diff, event stat information. While running docker sub-commands we need root privileges.
List Running Containers
In a busy environment there will be a lot of containers. Listing running containers are important part of the container management. We can list running containers with
$ docker ps
As we can see ps command provides following information about each running container
CONTAINER IDcolumn shows uniq ID of the container. This is is used for the most of the container operations like stop, clone, connect etc.
IMAGEcolumn show the base image used to create related container.
COMMANDcolumn shows the command running in the container while starting.
CREATEDcolumn shows how much time ago the container is created
STATUScolumns shows the uptime of the container.
PORTScolumns shows the redirected ports and related network configuration.
NAMEcolumn shows the human readable name of the container. If it is not given explicitly docker engine assign random name.
As we know docker containers are created from previously pulled and stored images. Images contains file system of the containers. We can list locally avaible images with the
-image sub command.
$ docker images
This command will list following information about the container images.
REPOSITORYcolumn shows the name and repository of the image
TAGcolumns shows related tags which is generally provides version information about the container image
IMAGE IDcolumn shows image unique identifier
CREATEDcolumns shows the creation time of the image
SZIEcolumn shows the size of the image
Show Containers Logs
Container will create docker engine related logs while running and operations. These log can be seen without searching them in directories with simple
logs command. We will also provide the container id to specify container we want to see logs. In this example the container id is feb2c71e09e8
$ docker logs feb2c71e09e8
Get Detailed Information About Running Container
One of the best feature of docker engine is that it can provide a lot of information about the running containers. these information is provided in
JSON format. We will use
inspect subocmmand to list all details about the container.
$ docker inspect feb2c71e09e8
As we can see there are enormous information. We will look some of the important of them below.
IDcolumn shows the container id
Stateline shows current state of the container
Mountsline shows mounted shares
NetworkSettingsline shows detailed information like IP address, default gateway etc.
Shown Container Events
Containers have different events during the work. These events can be viewed with
events sub-command. This command will start an real time console and print all events in real time like start, die, attach, resize events.
$ docker events
Show Network And Port Information
Network is important aspect for the containers. By default newly created containers will connect to the external networks and internet with a NAT. But docker engine also supports port mapping and IP address nat. We can list these existing NATS and port mapping with
port command. We will also provide the container ID.
$ docker port feb2c71e09e8
Show Container CPU Usage
As we know containers are not virtual machines. They are just processes running on the host with restricted status. So They get CPU time from the host system. We can list given containers CPU usage with top command. We will also provide the containers ID.
$ docker top a264a020b160
Show Container Resource Usage
If we need real time stats about the running containers we can use
stats command. This will give top like output in a simple way.
$ docker stats
Here are following information;
CONTAINERcolumn shows container id
CPUcolumn shows the current CPU usage
MEMUSAGEcolumn show memory usage
MEM %column shows the usage in percentage format
NET I/Ocolumn shows network I/O information.
BLOCK I/Ocolumn shows disk I/O information.
PIDScolumn shows total number of processes.