• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How To Get Information About a Container In Docker

by admin

Here is a short note on how to pull information of the container running on the host. This is similar to the “xm list –long [domain_ID]” command in xen.

Getting information from outside of the Docker Container

1. Below are the list of images that are residing on the host node.

# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
fedora              latest              422dc563ca32        2 days ago          252MB
ubuntu              latest              dd6f76d9cc90        13 days ago         122MB
hello-world         latest              725dcfab7d63        13 days ago         1.84kB
centos              latest              d123f4e55e12        13 days ago         197MB

2. Start one of the docker images.

# docker run -it -d 422dc563ca32 /bin/bash
52249ba75f0fa33f93202f4a2d7f83bc71600b8b75ea4db0bc5b56022bf254b6

3. Verify the new Docker container is running.

# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
52249ba75f0f        422dc563ca32        "/bin/bash"         About a minute ago   Up About a minute                       gracious_keller

The “inspect“” command will list the complete information of the container. Use the container ID listed in the first column with the inspect option. You will get a pretty long output here.

# docker inspect 52249ba75f0f
[
    {
        "Id": "52249ba75f0fa33f93202f4a2d7f83bc71600b8b75ea4db0bc5b56022bf254b6",
        "Created": "2017-11-17T14:38:05.340313315Z",
        "Path": "/bin/bash",
        "Args": [],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 1535,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2017-11-17T14:38:05.638951265Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        }
        .......

4. This can also be truncated based on what needs to be verified. For example, you could only get information on the networking part of the Docker Container.

# docker inspect --format='{{ .NetworkSettings.IPAddress }}' 52249ba75f0f
172.17.0.2
# docker inspect --format='{{ .NetworkSettings.Gateway }}' 52249ba75f0f
172.17.0.1

Getting Information from inside the Docker Container

The below example is to show the settings from inside the Docker container.

1. First, attach to the docker container.

# docker attach 52249ba75f0f

2. When you attach to a brand new container, commands like ifconfig, route will not work. As the docker is a bare minimal installation and we have to install the packages as and when they are required. So, to run ifconfig and route command, first install the net-tools package.

# yum install net-tools

3. Now run the commands ifconfig and route to get the required information about the Docker container.

# ifconfig -a
eth0: flags=4163[UP,BROADCAST,RUNNING,MULTICAST]  mtu 1500
        inet 172.17.0.2  netmask 255.255.0.0  broadcast 0.0.0.0
        ether 02:42:ac:11:00:02  txqueuelen 0  (Ethernet)
        RX packets 36502  bytes 72894961 (69.5 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 22286  bytes 1594850 (1.5 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
lo: flags=73[UP,LOOPBACK,RUNNING]  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.17.0.1      0.0.0.0         UG    0      0        0 eth0
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 eth0

Container config file

Also, the information about the container will be stored as config file and can be used to re-initiate the container. The path location for the container can be collected from the earlier “inspect” command.

Filed Under: DevOps, Docker

Some more articles you might also be interested in …

  1. How to write Bubble sort in Bash
  2. Run Docker as a non-root user
  3. How to Configure Btrfs as the Storage Engine in Docker
  4. Examples of creating command alias in different shells
  5. Korn Shell select Loop
  6. How to use command redirection under Linux
  7. Strings and Variables in Python
  8. How to Create a Public/Private Repository in Docker Hub and connect it remotely using command line
  9. “Error: Could Not Find A Ready Tiller Pod” – helm error
  10. How to Configure Nagios NRPE Client for System Monitoring (CentOS/RHEL)

You May Also Like

Primary Sidebar

Recent Posts

  • JavaFX ComboBox: Set a value to the combo box
  • Nginx load balancing
  • nginx 504 gateway time-out
  • Images preview with ngx_http_image_filter_module

© 2022 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright