ContainerPlatform Docker utilities#

The docker_operations.py module provides various utilities to manage Docker containers within the ContainerPlatform. These utilities include functions to validate, start, stop, and manage Docker containers, as well as to check Docker installation and daemon status.

Key functions#

  • validate_container_running(platform, **kwargs): Checks if the Docker daemon is running, finds an existing container, or starts a new container.

  • get_container(container_id): Retrieves the container object by container ID.

  • find_container_by_image(image, include_stopped=False): Finds containers that match the specified image.

  • stop_container(container, remove=True): Stops a container and optionally removes it.

  • stop_all_containers(containers, keep_running=True, remove=True): Stops all specified containers.

  • restart_container(container): Restarts a container.

  • sort_containers_by_start(containers, reverse=True): Sorts containers by their start time.

  • get_containers(include_stopped=False): Retrieves all containers, optionally including stopped ones.

  • get_working_containers(container_id=None, entity=False): Retrieves working containers.

  • is_docker_installed(): Checks if Docker is installed.

  • is_docker_daemon_running(): Checks if the Docker daemon is running.

  • check_local_image(image_name): Checks if the specified Docker image exists locally.

  • pull_docker_image(image_name, tag=’latest’): Pulls a Docker image from the repository.

  • compare_mounts(mounts1, mounts2): Compares two sets of mount configurations.

  • compare_container_mount(container1, container2): Compares the mount configurations of two containers.

  • list_running_jobs(container_id, limit=None): Lists all running jobs on the specified container.

  • find_running_job(item_id, container_id=None): Finds a running job by item ID and optionally container ID.

Usage#

These utilities are typically used to manage Docker containers within the idmtools_platform_container, ensuring that the necessary containers are running and properly configured for executing experiments and simulations.

Example#

from idmtools_platform_container.container_operations.docker_operations import (
    validate_container_running, get_container, stop_container
)

# Validate and start a container
container_id = validate_container_running(platform)

# Retrieve a container object
container = get_container(container_id)

# Stop a container
stop_container(container)