How To Get Information About Running Containers, Images In Docker? – POFTUT

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

$ docker ps
List Running Containers
List Running Containers

As we can see ps command provides following information about each running container

  • CONTAINER ID column shows uniq ID of the container. This is is used for the most of the container operations like stop, clone, connect etc.
  • IMAGE column show the base image used to create related container.
  • COMMAND column shows the command running in the container while starting.
  • CREATED column shows how much time ago the container is created
  • STATUS columns shows the uptime of the container.
  • PORTS columns shows the redirected ports and related network configuration.
  • NAME column shows the human readable name of the container. If it is not given explicitly docker engine assign random name.

List Images

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
List Images
List Images

This command will list following information about the container images.

  • REPOSITORY column shows the name and repository of the image
  • TAG columns shows related tags which is generally provides version information about the container image
  • IMAGE ID column shows image unique identifier
  • CREATED columns shows the creation time of the image
  • SZIE column shows the size of the image
LEARN MORE  How To Install Gns3 To Fedora?

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
Get Detailed Information About Running Container
Get Detailed Information About Running Container

As we can see there are enormous information. We will look some of the important of them below.

  • ID column shows the container id
  • State line shows current state of the container
  • Mounts line shows mounted shares
  • NetworkSettings line 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
Shown Container Events
Shown Container 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 CPU Usage
Show Container CPU Usage

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
Show Container Resource Usage
Show Container Resource Usage

Here are following information;

  • CONTAINER column shows container id
  • CPU column shows the current CPU usage
  • MEMUSAGE column show memory usage
  • MEM % column shows the usage in percentage format
  • NET I/O column shows network I/O information.
  • BLOCK I/O column shows disk I/O information.
  • PIDS column shows total number of processes.
LEARN MORE  How To Get Mac Addresses Of Hosts With Nmap?

1 thought on “How To Get Information About Running Containers, Images In Docker?”

Leave a Comment