docker
Docker image, container, orchestration, and cleanup helpers.
Examples:
>>> from ures.docker import Image
>>> image = Image("python", tag="3.12-slim")
>>> image.get_fullname()
'python:3.12-slim'
BuildConfig
Bases: BaseModel
BuildConfig defines the build parameters for constructing a Docker image.
Attributes:
-
base_image(str) –Base image for the container. Default is "python:3.10-slim".
-
platform(Optional[str]) –Target platform in format os[/arch[/variant]].
-
python_deps_manager(Optional[str]) –Package manager for Python dependencies (e.g., pip, conda).
-
python_dependencies(Optional[List[str]]) –List of Python packages to install.
-
sys_deps_manager(Optional[str]) –Package manager for system dependencies (e.g., apt, yum, apk).
-
sys_dependencies(Optional[List[str]]) –List of system packages to install.
-
labels(Optional[List[Tuple[str, str]]]) –List of key-value tuples used as labels.
-
uid(Optional[int]) –User ID to use inside the container.
-
user(Optional[str]) –Username to use inside the container.
-
entrypoint(Optional[List[str]]) –Entrypoint command for the container.
-
cmd(Optional[List[str]]) –Default command to run in the container.
-
environment(Optional[Dict[str, str]]) –Environment variables for the container.
-
copies(Optional[List[Dict[str, str]]]) –File copy instructions (each dict should include "src" and "dest").
-
context_dir(Union[str, Path]) –Directory for the build context. Defaults to the current working directory.
-
docker_filename(str) –Filename for the Dockerfile. Defaults to "Dockerfile".
Examples:
>>> config = BuildConfig()
>>> config.base_image
'python:3.10-slim'
add_label
add_label(key: str, value: str)
Add a label to the build configuration.
Parameters:
Examples:
>>> config = BuildConfig()
>>> config.add_label("version", "1.0")
>>> config.labels
[("version", "1.0")]
Source code in ures/docker/conf.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
add_copy
add_copy(src: str, dest: str)
Add a file copy instruction to the build configuration.
Parameters:
Examples:
>>> config = BuildConfig()
>>> config.add_copy("app.py", "/app/app.py")
>>> config.copies
[{"src": "app.py", "dest": "/app/app.py"}]
Source code in ures/docker/conf.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
add_environment
add_environment(key: str, value: str)
Add an environment variable to the build configuration.
Parameters:
Examples:
>>> config = BuildConfig()
>>> config.add_environment("DEBUG", "true")
>>> config.environment["DEBUG"]
'true'
Source code in ures/docker/conf.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
set_context_dir
set_context_dir(context_dir: Union[str, Path])
Set the build context directory.
Parameters:
Raises:
-
ValueError–If the provided context directory does not exist or is not a directory.
Examples:
>>> from pathlib import Path
>>> config = BuildConfig()
>>> temp_dir = Path("/tmp")
>>> config.set_context_dir(temp_dir)
>>> config.context_dir == temp_dir
True
Source code in ures/docker/conf.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
add_python_dependency
add_python_dependency(dependency: str)
Add a Python dependency to be installed in the image.
Parameters:
-
dependency(str) –The Python package dependency (e.g., "flask==2.0.1").
Examples:
>>> config = BuildConfig()
>>> config.add_python_dependency("flask")
>>> "flask" in config.python_dependencies
True
Source code in ures/docker/conf.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
add_system_dependency
add_system_dependency(dependency: str)
Add a system dependency to be installed in the image.
Parameters:
-
dependency(str) –The system package dependency (e.g., "curl").
Examples:
>>> config = BuildConfig()
>>> config.add_system_dependency("curl")
>>> "curl" in config.sys_dependencies
True
Source code in ures/docker/conf.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
add_run_command
add_run_command(command: str)
Add a command to be run during the build process.
Parameters:
-
command(str) –The command to run (e.g., "apt-get update").
Examples:
>>> config = BuildConfig()
>>> config.add_run_command("apt-get update")
>>> "apt-get update" in config.run_commands
True
Source code in ures/docker/conf.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
set_entrypoint
set_entrypoint(entrypoint: Union[str, List[str]])
Set the entrypoint for the container.
Parameters:
-
entrypoint(Union[str, List[str]]) –The entrypoint command(s). If a string is provided, it will be converted to a list.
Examples:
>>> config = BuildConfig()
>>> config.set_entrypoint("python app.py")
>>> config.entrypoint
["python app.py"]
Source code in ures/docker/conf.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | |
set_cmd
set_cmd(cmd: Union[str, List[str]])
Set the command for the container.
Parameters:
-
cmd(Union[str, List[str]]) –The command(s) to run. If a string is provided, it will be converted to a list.
Examples:
>>> config = BuildConfig()
>>> config.set_cmd("python -m myapp")
>>> config.cmd
["python -m myapp"]
Source code in ures/docker/conf.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
RuntimeConfig
Bases: BaseModel
RuntimeConfig defines the runtime parameters for running a Docker container.
Attributes:
-
image_name(str) –Name of the Docker image in the format "image:tag".
-
name(Optional[str]) –Container name.
-
platform(Optional[str]) –Platform for the container.
-
detach(bool) –Whether to run the container in detached mode.
-
user(Optional[str]) –User under which to run the container.
-
remove(bool) –Whether to remove the container after it stops.
-
cpus(Optional[int]) –Number of CPUs to allocate.
-
gpus(Optional[List[str]]) –List of GPUs to allocate.
-
gpu_driver(str) –Driver to use for GPUs. Default is "nvidia".
-
memory(Optional[str]) –Memory limit for the container (e.g., "2g").
-
entrypoint(Optional[List[Union[str, float, int, Path]]]) –Entrypoint command(s).
-
command(Optional[List[Union[int, float, str, Path]]]) –Command(s) to run.
-
env(Optional[Dict[str, str]]) –Environment variables.
-
volumes(Optional[Dict[str, Dict[str, str]]]) –Volume mappings.
-
subnet(Optional[str]) –Subnet for container networking.
-
ipv4(Optional[str]) –Specific IPv4 address for the container.
-
subnet_mask(Optional[str]) –Subnet mask (e.g., "172.17.0.0/16").
-
subnet_gateway(Optional[str]) –Subnet gateway.
-
network_mode(Optional[str]) –Docker network mode.
-
out_dir(Path) –Output directory for logs and cache.
Examples:
>>> config = RuntimeConfig()
>>> config.image_name
'model-runner'
log_dir
property
log_dir: Path
Get the log directory within the output directory. If it does not exist, it is created.
Returns:
-
Path(Path) –The path to the log directory.
Examples:
>>> config = RuntimeConfig()
>>> log_directory = config.log_dir
>>> log_directory.exists()
True
cache
property
cache: Path
Get the cache directory within the output directory. If it does not exist, it is created.
Returns:
-
Path(Path) –The path to the cache directory.
Examples:
>>> config = RuntimeConfig()
>>> cache_directory = config.cache
>>> cache_directory.exists()
True
add_volume
add_volume(host_path: Union[str, Path], container_path: Union[str, Path], mode: str = 'rw')
Add a volume mapping for the container.
Parameters:
-
host_path(Union[str, Path]) –The path on the host machine.
-
container_path(Union[str, Path]) –The destination path inside the container.
-
mode(str, default:'rw') –The mode for the volume mapping (e.g., "rw" or "ro"). Defaults to "rw".
Examples:
>>> config = RuntimeConfig()
>>> config.add_volume("/host/data", "/container/data", mode="rw")
>>> "/host/data" in config.volumes
True
Source code in ures/docker/conf.py
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 | |
add_env
add_env(key: str, value: str)
Add an environment variable for the container.
Parameters:
Examples:
>>> config = RuntimeConfig()
>>> config.add_env("DEBUG", "1")
>>> config.env["DEBUG"]
'1'
Source code in ures/docker/conf.py
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 | |
Container
Container(image: Image, client: Optional[DockerClient] = None)
A class to manage a Docker container.
This class provides methods to create a container with specified runtime configurations, manage network connections, and control the container's lifecycle (start, stop, remove, logs, wait).
Attributes:
-
_image(Image) –The Docker image object to be used.
-
_client(DockerClient) –The Docker client instance.
-
_container(Optional[Container]) –The underlying Docker container object.
Initialize a Container instance.
Parameters:
-
image(Image) –The Image object that provides the Docker image details.
-
client(Optional[DockerClient], default:None) –An optional Docker client instance. If not provided, docker.from_env() is used.
Examples:
>>> from ures.docker.image import Image
>>> img = Image("myapp")
>>> container = Container(img)
Source code in ures/docker/container.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
image_name
property
image_name: str
Retrieve the full image name (including tag).
Returns:
-
str(str) –The full image name.
Examples:
>>> container.image_name
'myapp:latest'
is_created
property
is_created: bool
Check whether the container has been created.
Returns:
-
bool(bool) –True if the container exists, False otherwise.
Examples:
>>> container.is_created
False
status
property
status: str
Get the current status of the container.
Returns:
-
str(str) –The container status. If not found, returns "removed".
Examples:
>>> status = container.status
>>> status in ["created", "running", "exited", "removed"]
True
exit_code
property
exit_code: int | None
Retrieve the exit code of the container's last run.
Returns:
-
int | None–The exit code if Docker still knows the container, otherwise None.
Examples:
>>> code = container.exit_code
>>> isinstance(code, int) or code is None
True
is_running
property
is_running: bool
Check if the container is currently running.
Returns:
-
bool(bool) –True if running, False otherwise.
Examples:
>>> container.is_running
True
create
create(config: RuntimeConfig, tag: Optional[str] = None)
Create a Docker container using the provided runtime configuration.
Parameters:
-
config(RuntimeConfig) –The runtime configuration for the container.
-
tag(Optional[str], default:None) –An optional image tag override. Defaults to None.
Examples:
>>> container.create(runtime_config)
>>> container.is_created
True
Source code in ures/docker/container.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
stop
stop()
Stop the running container.
Examples:
>>> container.stop()
Source code in ures/docker/container.py
283 284 285 286 287 288 289 290 291 292 | |
remove
remove()
Remove the container.
Examples:
>>> container.remove()
Source code in ures/docker/container.py
294 295 296 297 298 299 300 301 302 303 304 | |
logs
logs() -> bytes
Retrieve logs from the container.
Returns:
-
bytes–Raw log output from the Docker SDK.
Examples:
>>> logs = container.logs()
>>> isinstance(logs, bytes)
True
Source code in ures/docker/container.py
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | |
wait
wait()
Wait for the container to finish execution.
Blocks until the Docker container stops. The Docker SDK result is not
returned; inspect exit_code afterwards if you need the status.
Examples:
>>> container.wait()
Source code in ures/docker/container.py
322 323 324 325 326 327 328 329 330 331 332 333 334 | |
run
run()
Start the container if it has been created and is not already running.
Raises:
-
RuntimeError–If the container has not been created or is already running.
Examples:
>>> container.run()
>>> container.is_running
True
Source code in ures/docker/container.py
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 | |
Containers
Containers(image: Image, client: Optional[DockerClient] = None, runtime: type(Runtime) = SimpleRuntime)
Manages the creation and lifecycle of Docker container instances derived from a given Docker image.
This class provides methods to create new container instances using a default or customized runtime configuration, run those containers using a specified runtime (default is SimpleRuntime), and then stop and remove them while maintaining a history of container records and their configurations.
Parameters:
-
image(Image) –An instance of the Image class representing the Docker image to be used.
-
client(Optional[DockerClient], default:None) –A Docker client instance. Defaults to docker.from_env().
-
runtime(type(Runtime), default:SimpleRuntime) –The runtime class used to manage container operations. Must be a subclass of Runtime. Defaults to SimpleRuntime.
Attributes:
-
_client(DockerClient) –The Docker client instance.
-
_image(Image) –The Docker image used for creating containers.
-
_runtime_history(Dict[str, Dict[str, Union[Container, str]]]) –A dictionary storing records of created container instances and their associated runtime configurations, keyed by a unique container name.
-
_runtime(type(Runtime) –The runtime class used for managing container lifecycle operations.
Methods:
-
get_container–bool = False) -> List[Tuple[str, Dict[str, Union[Container, str]]]]: Retrieve container records from the history. If
newis True, returns only records whose container status is "created". -
_default_config–Generates a default RuntimeConfig based on the image and a generated unique container name.
-
_construct_config–Constructs a RuntimeConfig by updating the default configuration with provided keyword arguments.
-
_add_record–Container, config: RuntimeConfig) -> None: Adds a record for a newly created container and its configuration to the runtime history.
-
create–Creates a new container using the provided configuration keyword arguments, records it in the history, and returns the container.
-
run–Runs all newly created containers using the specified runtime and returns their records.
-
stop–Optional[Union[str, Path]] = None) -> List[Tuple[str, Dict[str, Union[Container, str]]]]: Stops all managed containers, collects their logs (saving them to the specified directory), removes them, and returns the updated container records.
Examples:
>>> from ures.docker.image import Image
>>> from ures.docker.containers import Containers
>>> from ures.docker.conf import RuntimeConfig
>>> img = Image("myapp", tag="latest")
>>> containers_manager = Containers(image=img)
>>> container = containers_manager.create(name="myapp-instance")
>>> containers_manager.run()
>>> containers_manager.stop("/tmp/container_logs")
Source code in ures/docker/containers.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
image
property
image: str
Returns the full image name including the tag.
Returns:
-
str(str) –The full image name.
Examples:
>>> containers_manager.image
'myapp:latest'
name
property
name: str
Generates a unique container name.
Returns:
-
str–A name of the form
{image.name}-instance-{unique_id}.
Examples:
>>> containers_manager.name
'myapp-instance-abc123def4'
history
property
history: Dict[str, Dict[str, Union[Container, str]]]
Retrieves the history of container records.
Returns:
-
Dict[str, Dict[str, Union[Container, str]]]–Dict[str, Dict[str, Union[Container, str]]]: A dictionary of container records keyed by unique names.
Examples:
>>> containers_manager.history
{'myapp-instance-abc123def4': {'container': <Container object>, 'config': <RuntimeConfig>}}
get_container
get_container(new: bool = False) -> List[Tuple[str, Dict[str, Union[Container, str]]]]
Retrieve container records from the history.
Parameters:
-
new(bool, default:False) –If True, only return container records whose container status is "created". Defaults to False.
Returns:
-
List[Tuple[str, Dict[str, Union[Container, str]]]]–List[Tuple[str, Dict[str, Union[Container, str]]]]: A list of tuples containing the container's unique name
-
List[Tuple[str, Dict[str, Union[Container, str]]]]–and its record.
Examples:
>>> records = containers_manager.get_container(new=True)
Source code in ures/docker/containers.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
create
create(**kwargs) -> Container
Create a new container instance using the specified configuration.
Parameters:
-
**kwargs(Any, default:{}) –RuntimeConfig fields to override, such as name or detach.
Returns:
-
Container(Container) –The newly created container instance.
Examples:
>>> container = containers_manager.create(name="instance1")
Source code in ures/docker/containers.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
run
run() -> List[Tuple[str, Dict[str, Union[Container, str]]]]
Run all newly created containers using the specified runtime.
Returns:
-
List[Tuple[str, Dict[str, Union[Container, str]]]]–List[Tuple[str, Dict[str, Union[Container, str]]]]: The list of container records that were run.
Examples:
>>> records = containers_manager.run()
Source code in ures/docker/containers.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
stop
stop(log_dir: Optional[Union[str, Path]] = None) -> List[Tuple[str, Dict[str, Union[Container, str]]]]
Stop all managed containers, collect their logs (saving them to the specified directory), and remove them.
Parameters:
-
log_dir(Optional[Union[str, Path]], default:None) –The directory where container logs will be saved. If not provided, a default temporary directory is used.
Returns:
-
List[Tuple[str, Dict[str, Union[Container, str]]]]–List[Tuple[str, Dict[str, Union[Container, str]]]]: The updated container records after stopping and removal.
Examples:
>>> records = containers_manager.stop("/tmp/container_logs")
Source code in ures/docker/containers.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |
Image
Image(image_name: str, tag: Optional[str] = None, client: DockerClient = None)
Represents and manages a Docker image.
Attributes:
-
_image_name(str) –The name of the Docker image.
-
_tag(str) –The tag of the Docker image (default is "latest").
-
_client(DockerClient) –The Docker client instance.
-
_image(Optional[Image]) –The Docker image object if available.
Initializes an Image instance.
Parameters:
-
image_name(str) –The name of the Docker image.
-
tag(Optional[str], default:None) –The image tag. Defaults to "latest" if not provided.
-
client(Optional[DockerClient], default:None) –The Docker client to use. Defaults to docker.from_env().
Examples:
>>> img = Image("myapp", tag="v1")
Source code in ures/docker/image.py
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
name
property
name: str
Gets the name of the image.
Returns:
-
str(str) –The image name.
Examples:
>>> img = Image("myapp")
>>> img.name
'myapp'
tag
property
tag: str
Gets the tag of the image.
Returns:
-
str(str) –The image tag.
Examples:
>>> img = Image("myapp", tag="v1")
>>> img.tag
'v1'
exist
property
exist: bool
Checks if the image exists locally.
Returns:
-
bool(bool) –True if the image exists, False otherwise.
Examples:
>>> img = Image("myapp")
>>> img.exist # Depends on local Docker images
image
property
image: Optional[Image]
Gets the Docker image object.
Returns:
-
Optional[Image]–Optional[DockerImage]: The Docker image object if found, otherwise None.
Examples:
>>> img = Image("myapp")
>>> img.image # Might return a DockerImage object if available
id
property
id: str
Gets the unique ID of the Docker image.
Returns:
-
str(str) –The Docker image ID.
Examples:
>>> img = Image("myapp")
>>> img.id
'sha256:...'
architecture
property
architecture: str
Gets the architecture of the Docker image.
Returns:
-
str(str) –The image architecture (e.g., 'amd64').
Examples:
>>> img = Image("myapp")
>>> img.architecture
'amd64'
image_size
property
image_size: int
Gets the size of the Docker image in bytes.
Returns:
-
int(int) –The size of the image in bytes.
Examples:
>>> img = Image("myapp")
>>> img.image_size
12345678
labels
property
labels: dict
Gets the labels of the Docker image.
Returns:
-
dict(dict) –A dictionary of image labels.
Examples:
>>> img = Image("myapp")
>>> img.labels
{'version': '1.0'}
get_fullname
get_fullname(tag: Optional[str] = None) -> str
Constructs the full image name including the tag.
Parameters:
Returns:
-
str(str) –The full image name in the format "name:tag".
Examples:
>>> img = Image("myapp", tag="v1")
>>> img.get_fullname()
'myapp:v1'
Source code in ures/docker/image.py
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 | |
get_image
get_image(tag: Optional[str] = None) -> Optional[DockerImage]
Retrieves the Docker image from the local repository.
Parameters:
-
tag(Optional[str], default:None) –The tag to use when retrieving the image. Defaults to the instance's tag.
Returns:
-
Optional[Image]–Optional[DockerImage]: The Docker image if found; otherwise, None.
Examples:
>>> img = Image("myapp")
>>> image_obj = img.get_image()
>>> image_obj is not None # Depends on local Docker images
Source code in ures/docker/image.py
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 | |
pull_image
pull_image(tag: Optional[str] = None) -> Optional[DockerImage]
Pulls the Docker image from a remote repository.
Parameters:
-
tag(Optional[str], default:None) –The tag to pull; defaults to the instance's tag if not provided.
Returns:
-
Optional[Image]–Optional[DockerImage]: The pulled Docker image if successful; otherwise, None.
Examples:
>>> img = Image("myapp")
>>> pulled = img.pull_image()
>>> pulled is not None
Source code in ures/docker/image.py
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 | |
build_image
build_image(build_config: BuildConfig, dest: Union[str, Path], build_context: Optional[Union[str, Path]] = None) -> DockerImage
Builds a Docker image using the specified build configuration.
Parameters:
-
build_config(BuildConfig) –The configuration for building the image.
-
dest(Union[str, Path]) –The destination path where the Dockerfile will be saved.
-
build_context(Optional[Union[str, Path]], default:None) –The build context directory. Defaults to build_config.context_dir.
Returns:
-
DockerImage(Image) –The built Docker image.
Examples:
>>> build_config = BuildConfig()
>>> img = Image("myapp")
>>> built_img = img.build_image(build_config, "/tmp/dockerfile_dir")
>>> built_img is not None
True
Source code in ures/docker/image.py
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 | |
remove
remove(tag: Optional[str] = None, force: bool = False, noprune: bool = False)
Removes the Docker image from the local repository.
Parameters:
-
tag(Optional[str], default:None) –The tag to remove. Defaults to the instance's tag.
-
force(bool, default:False) –Force removal. Defaults to False.
-
noprune(bool, default:False) –Do not remove untagged parent images. Defaults to False.
Examples:
>>> img = Image("myapp")
>>> img.remove()
Source code in ures/docker/image.py
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 | |
info
info()
Prints detailed information about the Docker image.
Examples:
>>> img = Image("myapp")
>>> img.info()
Source code in ures/docker/image.py
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 | |
ImageOrchestrator
ImageOrchestrator(client: Optional[DockerClient] = None)
Orchestrates the building of multiple Docker images considering their dependencies.
Attributes:
-
_client(DockerClient) –The Docker client instance.
-
_images(dict) –A dictionary holding images and their build configuration and status.
Initializes the ImageOrchestrator.
Parameters:
-
client(Optional[DockerClient], default:None) –The Docker client instance. Defaults to docker.from_env().
Examples:
>>> orchestrator = ImageOrchestrator()
Source code in ures/docker/image.py
638 639 640 641 642 643 644 645 646 647 648 649 650 651 | |
images
property
images: Dict[str, Dict[str, Union[Optional[Image], BuildConfig, str]]]
add_image
add_image(image: Image, config: BuildConfig, base: Image = None) -> bool
Adds an image and its build configuration to the orchestrator.
Parameters:
-
image(Image) –The Image instance to add.
-
config(BuildConfig) –The build configuration for the image.
-
base(Image, default:None) –The base image that this image depends on, if any.
Returns:
-
bool–True if the image was registered in the orchestrator.
Examples:
>>> orch = ImageOrchestrator()
>>> img = Image("myapp")
>>> config = BuildConfig()
>>> orch.add_image(img, config)
True
Source code in ures/docker/image.py
667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 | |
build_all
build_all()
Builds all registered images in the correct order based on dependencies.
Examples:
>>> orchestrator.build_all()
Source code in ures/docker/image.py
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 | |
DockerCleanup
DockerCleanup(client: Optional[DockerClient] = None)
Remove dangling images and leftover containers from the local Docker engine.
Examples:
>>> from ures.docker import DockerCleanup
>>> cleanup = DockerCleanup()
>>> cleanup.dangling_images()
>>> cleanup.stopped_containers()
Attach to a Docker client.
Parameters:
-
client(DockerClient | None, default:None) –A Docker SDK client. Defaults to
docker.from_env().
Source code in ures/docker/cleanup.py
15 16 17 18 19 20 21 22 | |
dangling_images
dangling_images()
Delete dangling (untagged) local images.
Source code in ures/docker/cleanup.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
stopped_containers
stopped_containers()
Delete containers in exited or created state.
Source code in ures/docker/cleanup.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |