build.build()

Build a Docker image from a Dockerfile.

Usage

build.build(
    dockerfile=Path(".") / "Dockerfile",
    image_name="tugboat",
    tag="latest",
    platforms=["linux/amd64", "linux/arm64"],
    build_args=None,
    build_context=str(Path(".").resolve()),
    push=False,
    dh_username=None,
    dh_password=None,
    verbose=False
)

Parameters

dockerfile: str or Path = Path(".") / "Dockerfile"

Path to the Dockerfile to build.

image_name: str = "tugboat"

Name to assign to the built Docker image.

tag: str = "latest"

Tag to assign to the built Docker image.

platforms: list of str or str = ["linux/amd64", "linux/arm64"]

One or more target platforms to build the image for.

build_args: list of str or None = None

Additional arguments to pass through to docker buildx build.

build_context: str = current working directory

Path to the build context directory.

push: bool = False

Whether to push the built image to DockerHub. If True, both dh_username and dh_password must be provided.

dh_username: str or None = None

DockerHub username. Required if push is True.

dh_password: str or None = None

DockerHub password. Required if push is True.

verbose: bool = False
Whether to print the underlying docker buildx build command before executing it.

Returns

str
The full image reference, in the form {repository}:{tag}.

Raises

DockerNotFoundError

If Docker is not installed.

RuntimeError
If push is True but dh_username or dh_password is missing, if the Docker login fails, or if the build fails.