Skip to main content

DOCKERINFO

PyPI - Downloads per month Pepy Total Downlods

Easily extract information from docker containers

Since version 1.2 can extract containers logs.

Example:

from dockerinfo.docker_info import DockerContainerInfo, DockerHelper

# Create an instance of the DockerHelper class and list the existing containers.
# Use all_containers=True/False to list inactive containers.
docker_info = DockerHelper()
container_list = docker_info.list_containers(all_containers=True)

# Iterate through all found containers and extract information.
print(">>> ITERATING THROUGH ALL EXISTING CONTAINERS AND EXTRACTING INFORMATION")
for container in container_list:
    container_info = DockerContainerInfo(container)
    print(f"Container ID: {container_info.id}")
    print(f"Container Name: {container_info.name}")
    print(f"Container Status: {container_info.status}")
    print(f"Container Log (last 5 lines):")
    for log_line in container_info.get_logs_tail(5):
        print(log_line)

# Extract information from a specific container (in this case, 'test01').
print("
>>> LOOKING FOR A SPECIFIC CONTAINER (test01)")
container = docker_info.get_container_by_name('test01')

if container:
    # If the container is found, create an instance of the DockerContainerInfo class.
    container_info = DockerContainerInfo(container)

    # Print container information.
    print(f"Container ID: {container_info.id}")
    print(f"Container Name: {container_info.name}")
    print(f"Container Status: {container_info.status}")

    # Test other methods of the DockerContainerInfo class as needed.
    print(f"Networks (all): {container_info.networks}")

    network_name = 'bridge'  # Change the network name as needed.
    network_info = container_info.get_network_config(network_name)
    print(f"Network Info for {network_name}: {network_info}")

    ip_address = container_info.get_network_attribute(network_name, 'IPAddress')
    mac_address = container_info.get_network_attribute(network_name, 'MacAddress')
    print(f"IP Address: {ip_address}, Mac Address: {mac_address}")

    # Print more container information as needed.
else:
    print("Container not found: test01")

Available options:

  • id

Returns the container ID.

  • name

Returns the container name.

  • status

Returns the current status of the container.

  • config

Returns the entire configuration of the container.

  • hostname

Returns the container’s hostname.

  • domainname

Returns the container’s domain name.

  • stopsignal

Returns the stop signal of the container.

  • networks

Returns the configuration of all networks of the container.

  • get_network_config(network)

Returns the configuration of a specific network of the container.

  • get_network_attribute(network, attribute)

Returns a specific attribute of a network of the container.

  • mounted_volumes

Returns the configuration of volumes mounted in the container.

  • get_logs Get the logs of the container, split into lines. Return a list containing each line of the container’s logs as a string.

  • get_logs_since(timestamp) Get the logs of the container since a specified timestamp, split into lines.

Args:

timestamp (int): The Unix timestamp from which to start fetching logs.

Return a list containing each line of the container’s logs as a string.

  • get_logs_since_date(date_string) Get the logs of the Docker container since a specified date.

Args: date_string: A string representing the date in MM/DD/YYYY format.

Returns the logs since the specified date.

Example:

logs_since_date = instance.get_logs_since_date("01/15/2023")

Note: The date string must be in the correct format to avoid conversion errors

  • get_logs_tail(lines)

Get the last N lines of the container’s logs, split into lines.

Args:

lines (int): The number of lines to retrieve from the end of the logs.

Returns:

Returns a list containing each line of the container’s logs as a string.

Metadata

Release files for dockerinfo 1.4.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dockerinfo 1.4.3
File Size Uploaded
dockerinfo-1.4.3.tar.gz 43.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dockerinfo 1.4.3
File Interpreter ABI Platform
dockerinfo-1.4.3-py3-none-any.whl Python 3 none any Details

Total release size: 72.0 kB

Release files / dockerinfo-1.4.3.tar.gz

Download URL dockerinfo-1.4.3.tar.gz
Size 43.1 kB
Tags Source
SHA-256 checksum
How to use checksums
88624190443fedbb8d5f62c2d0f61ef650f3de3533e842c079f5bfb83100c07b
BLAKE2b-256 checksum
How to use checksums
9e01ede33b12525e7243e391b0916d8dc3aa68abeb21aa0e355ac1f9d7677642
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release files / dockerinfo-1.4.3-py3-none-any.whl

Download URL dockerinfo-1.4.3-py3-none-any.whl
Size 28.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
593ccda5582d7b3a1fef1be57dda2d9c1c671c4b472cc479d43b47088088a54c
BLAKE2b-256 checksum
How to use checksums
124a40be8e8d5767c24df66de95613078ed94a3808a060f0dd4c922e8c492d8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release history Release notifications | RSS feed

This release

1.4.3 This release

2 release files

1.4.2

2 release files

1.4

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1

2 release files

1.0

2 release files

0.2

2 release files

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page