Skip to content

Client Module

This module provides base objects to manage docker containers.

Client

A Docker Client.

Provides the methods to connect to a docker engine.

Attributes:

  • client ClassVar[DockerClient] - A shared docker client session.

get_client

 | def get_client(cls) -> DockerClient

Return the docker client.

Config

Pydantic Configuration.

ContainerOptions

Docker Container Options.

Provides common options needed to start a docker container.

Attributes:

  • container_timeout ClassVar[int] - Timeout in seconds to wait for the container to stop before sending a SIGKILL.
  • image Optional[str] - Name of docker image.
  • auto_remove bool - Enable auto-removal of the container on daemon side when the container’s process exits.
  • detach bool - Run container in the background and return a Container object.
  • mounts List[DockerMount] - Specification for mounts to be added to the container.
  • ports Dict[int, int] - Ports to bind inside the container.

ContainerBase

Docker Container Base with default options and commonly used methods.

Attributes:

  • container_options ContainerOptions - ContainerOptions Object.
  • container Optional[Container] - Holds an instance of a initiated docker container.

container_id

 | def container_id() -> str

Return container instance id.

container_short_id

 | def container_short_id() -> str

Return container instance short id.

container_name

 | def container_name() -> str

Return container instance name.

container_timeout

 | def container_timeout() -> int

Return container timeout.

show_follow_logs_command

 | def show_follow_logs_command() -> None

Print log message with docker container logs command.

expose_port

 | def expose_port(port: int) -> None

Add ports to expose to the container options.

Arguments:

  • port int - The port to expose.

start

 | def start(show_log: bool = False) -> None

Start a container instance.

Arguments:

  • show_log bool - If True shows the containers logs.

restart

 | def restart() -> None

Restart the container instance.

 | def print_logs() -> None

Print the container instance logs.

stop

 | def stop(show_log: bool = False) -> None

Stop a container instance.

Arguments:

  • show_log bool - If True shows the containers logs.