Running in containers#

When running containers in your problems, engibench provides a container runtime abstraction, currently supporting

The following functions will use the first available container runtime in the order: docker, podman, singularity, or the runtime specified by the environment variable CONTAINER_RUNTIME if it is set:

engibench.utils.container.pull() None[source]#

Pull an image using the selected runtime.

Parameters:

image – Container image to pull.

engibench.utils.container.run(image: str, mounts: Sequence[tuple[str, str]] = (), env: dict[str, str] | None = None, name: str | None = None) None[source]#

Run a command in a container using the selected runtime.

Parameters:
  • command – Command (as a list of strings) to run inside the container.

  • image – Container image to use.

  • mounts – Pairs of host folder and destination folder inside the container.

  • env – Mapping of environment variable names and values to set inside the container.

  • name – Optional name for the container (not supported by all runtimes).

Alternatively the following runtimes can be used directly:

class engibench.utils.container.Docker[source]#

Bases: ContainerRuntime

Docker 🐋 runtime.

class engibench.utils.container.Podman[source]#

Bases: Docker

Podman 🦭 runtime.

class engibench.utils.container.Singularity[source]#

Bases: ContainerRuntime

Singularity / Apptainer.

All above container runtimes share the same interface:

class engibench.utils.container.ContainerRuntime[source]#

Abstraction over container runtimes.

classmethod is_available() bool[source]#

Check if the container runtime is installed and executable.

Returns:
  • `True` if the container runtime appears to be installed on the system and if required daemons are running,

  • `false` otherwise.

classmethod pull(image: str) None[source]#

Pull an image.

Parameters:

image – Container image to pull.

classmethod run(command: list[str], image: str, mounts: Sequence[tuple[str, str]] = (), env: dict[str, str] | None = None, name: str | None = None) subprocess.CompletedProcess[source]#

Run a command in a container.

Parameters:
  • command – Command (as a list of strings) to run inside the container.

  • image – Container image to use.

  • mounts – Pairs of host folder and destination folder inside the container.

  • env – Mapping of environment variable names and values to set inside the container.

  • name – Optional name for the container (not supported by all runtimes).