autonomy_toolkit.containers.docker_client#

Helpful utilities for interacting with docker.

Module Contents#

Classes#

DockerClient

Client interface for interacting with docker compose orchestration.

exception ContainerException(message: Any, stdout: str = None, stderr: str = None)[source]#

Bases: Exception

Exception class that is used by the ContainerClient when an error occurs

Parameters:
  • message (Any) – The message to be stored in the base class Exception

  • stdout (str) – The stdout from the command

  • stderr (str) – The stderr from the command

class DockerClient(config: autonomy_toolkit.utils.atk_config.ATKConfig, *, dry_run: bool = False, opts: List[str] = [], args: List[str] = [])[source]#

Client interface for interacting with docker compose orchestration.

Parameters:
  • config (ATKConfig) – The ATK configuration object.

  • dry_run (bool) – Whether to actually run the commands or just print them. Use DEBUG logging level to see the commands.

  • opts (List[str]) – Options to pass to the docker compose command.

  • args (List[str]) – Arguments to pass to the docker compose <command> command.

down() bool[source]#

Bring down the containers.

Returns:

bool – Whether the command succeeded.

build() bool[source]#

Build the images.

Returns:

bool – Whether the command succeeded.

up() bool[source]#

Bring up the containers.

Returns:

bool – Whether the command succeeded.

run() bool[source]#

Run a command in a container.

Returns:

bool – Whether the command succeeded.

attach() bool[source]#

Attach to a container.

NOTE: We assume a shell session is desired.

This is somewhat difficult, as we don’t know the default shell of the user in the container. We therefore have to determine this at runtime with a pretty nasty command.

Returns:

bool – Whether the command succeeded.

run_cmd(cmd, *args, without_ots: bool = False, **kwargs) bool[source]#

Run a command using the system wide compose command

Additional positional args (*args) will be passed as command arguments when running the command. Named arguments will be passed to subprocess.run() (see their docs).

Parameters:

cmd (str) – The command to run.

Returns:

Bool – Whether the command succeeded.

run_compose_cmd(*args, **kwargs) bool[source]#

Run a docker compose command.