image_build — Build Images Dynamically¶
- image_build.build_image(docker_client: DockerClient, image_name: str | None, remove_image: bool = True, output: IO[str] = sys.stderr, spinner: bool = True, **kwargs) AbstractContextManager[str][source]¶
Builds a docker image from a Dockerfile. Returns a context manager that optionally deletes the image when it exits.
- Parameters:
docker_client – A docker client to use to build the image.
image_name – The name of the image to build. If no tag is provided, the tag “test” will be added to the final image. If the image name is
None, an anonymous image will be created (without a tag).remove_image – Whether to remove the image after exiting the context.
output – The file to write build output to. Set to
Noneto disable printing the output, and to enable the spinner.spinner – Whether to show a spinner while building the image. Note that this will be disabled unless
outputisNone.**kwargs – Additional keyword arguments to pass to the
build()method.file – Legacy alias for
output.
- Returns:
A context manager that yields the image name with tag, and optionally deletes the image when it exits.
- image_build.async_build_image(docker_client: DockerClient, image_name: str, remove_image: bool = True, output: IO[str] = sys.stderr, spinner: bool = True, **kwargs) AbstractAsyncContextManager[str][source]¶
Builds a docker image from a Dockerfile. Returns an asyncronous context manager that optionally deletes the image when it exits.
- Parameters:
docker_client – A docker client to use to build the image.
image_name – The name of the image to build. If no tag is provided, the tag “test” will be added to the final image. If the image name is
None, an anonymous image will be created (without a tag).remove_image – Whether to remove the image after exiting the context.
output – The file to write build output to. Set to
Noneto disable printing the output, and to enable the spinner.spinner – Whether to show messages when building the image. The messages will be printed to
output.**kwargs – Additional keyword arguments to pass to the
build()method.
- Returns:
An async context manager that yields the image name with tag, and optionally deletes the image when it exits.