Skip to content

Dockerctl

DockerCtl

This class manages the creation and uploading of Docker containers.

Attributes:

Name Type Description
base_image str

The base image to use for the Docker container.

workdir str

The working directory in the Docker container.

local_dir str

The local directory to copy into the Docker container.

packages List[str]

List of packages to install in the Docker container.

os_packages List[str]

List of OS packages to install in the Docker container.

env_vars Dict[str, str]

Environment variables to set in the Docker container.

Command-Line Interface

genius docker package [options]

Parameters:

Name Type Description Default
- <image_name>

The name of the Docker image to build and upload.

required
- <repository>

The container repository to upload to (e.g., "ECR", "DockerHub", "Quay", "ACR", "GCR").

required
Options
  • --auth: Authentication credentials as a JSON string. Default is an empty JSON object.
  • --base_image: The base image to use for the Docker container. Default is "nvidia/cuda:12.2.0-runtime-ubuntu20.04".
  • --workdir: The working directory in the Docker container. Default is "/app".
  • --local_dir: The local directory to copy into the Docker container. Default is ".".
  • --packages: List of Python packages to install in the Docker container. Default is an empty list.
  • --os_packages: List of OS packages to install in the Docker container. Default is an empty list.
  • --env_vars: Environment variables to set in the Docker container. Default is an empty dictionary.
Authentication Details
  • ECR: {"aws_region": "ap-south-1", "aws_secret_access_key": "aws_key", "aws_access_key_id": "aws_secret"}
  • DockerHub: {"dockerhub_username": "username", "dockerhub_password": "password"}
  • ACR: {"acr_username": "username", "acr_password": "password", "acr_login_server": "login_server"}
  • GCR: {"gcr_key_file_path": "/path/to/keyfile.json", "gcr_repository": "repository"}
  • Quay: {"quay_username": "username", "quay_password": "password"}

Examples

Uploading to ECR (Amazon Elastic Container Registry)
genius docker package geniusrise ecr --auth '{"aws_region": "ap-south-1"}'
Uploading to DockerHub
genius docker package geniusrise dockerhub --auth '{"dockerhub_username": "username", "dockerhub_password": "password"}'

This is how we upload to dockerhub:

export DOCKERHUB_USERNAME=
export DOCKERHUB_PASSWORD=

genius docker package geniusrise dockerhub \
    --packages geniusrise-listeners geniusrise-databases geniusrise-huggingface geniusrise-openai \
    --os_packages libmysqlclient-dev libldap2-dev libsasl2-dev libssl-dev
genius docker package geniusrise-core dockerhub
Uploading to ACR (Azure Container Registry)
genius docker package geniusrise acr --auth '{"acr_username": "username", "acr_password": "password", "acr_login_server": "login_server"}'
Uploading to GCR (Google Container Registry)
genius docker package geniusrise gcr --auth '{"gcr_key_file_path": "/path/to/keyfile.json", "gcr_repository": "repository"}'

__init__()

Initialize the DockerContainerManager with logging.

build_image(image_name, dockerfile_path)

Build a Docker image based on the provided Dockerfile.

Parameters:

Name Type Description Default
image_name str

The name to give to the built Docker image.

required
dockerfile_path str

The path to the Dockerfile to use for building the image.

required

Returns:

Name Type Description
bool

True if the build was successful, False otherwise.

create_dockerfile()

Create a Dockerfile based on the class attributes.

Returns:

Name Type Description
str str

The path to the created Dockerfile.

create_parser(parser)

Add arguments to the command-line parser for managing Docker containers.

Parameters:

Name Type Description Default
parser argparse.ArgumentParser

Command-line parser.

required

Returns:

Type Description
argparse.ArgumentParser

argparse.ArgumentParser: The updated parser.

run(args)

Run the command-line interface.

Parameters:

Name Type Description Default
args argparse.Namespace

Parsed command-line arguments.

required

upload_to_acr(image_name, auth)

Upload the Docker image to Azure Container Registry (ACR).

Parameters:

Name Type Description Default
image_name str

The name of the Docker image to upload.

required
auth dict

Authentication credentials for ACR.

required

Returns:

Name Type Description
bool bool

True if the upload was successful, False otherwise.

upload_to_dockerhub(image_name, auth)

Upload the Docker image to DockerHub.

Parameters:

Name Type Description Default
image_name str

The name of the Docker image to upload.

required
auth dict

Authentication credentials for DockerHub.

required

Returns:

Name Type Description
bool bool

True if the upload was successful, False otherwise.

upload_to_ecr(image_name, auth, ecr_repo=None)

Upload the Docker image to Amazon Elastic Container Registry (ECR).

Parameters:

Name Type Description Default
image_name str

The name of the Docker image to upload.

required
auth dict

Authentication credentials for ECR.

required
ecr_repo Optional[str]

The ECR repository to upload to. If not provided, it will be generated.

None

Returns:

Name Type Description
bool bool

True if the upload was successful, False otherwise.

upload_to_gcr(image_name, auth)

Upload the Docker image to Google Container Registry (GCR).

Parameters:

Name Type Description Default
image_name str

The name of the Docker image to upload.

required
auth dict

Authentication credentials for GCR.

required

Returns:

Name Type Description
bool bool

True if the upload was successful, False otherwise.

upload_to_quay(image_name, auth)

Upload the Docker image to Quay.io.

Parameters:

Name Type Description Default
image_name str

The name of the Docker image to upload.

required
auth dict

Authentication credentials for Quay.io.

required

Returns:

Name Type Description
bool bool

True if the upload was successful, False otherwise.

upload_to_repository(image_name, repository, auth={})

Upload the Docker image to a specified container repository.

Parameters:

Name Type Description Default
image_name str

The name of the Docker image to upload.

required
repository str

The container repository to upload to (e.g., "ECR", "DockerHub", "Quay").

required
auth dict

Authentication credentials for the container repository. Defaults to None.

{}

Returns:

Name Type Description
bool bool

True if the upload was successful, False otherwise.