Docker Wrapper
Container
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:
| Name | Type | Description |
|---|---|---|
_image |
Image
|
The Docker image object to be used. |
_client |
DockerClient
|
The Docker client instance. |
_container |
Optional[Container]
|
The underlying Docker container object. |
Source code in ures/docker/container.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | |
exit_code
property
Retrieve the exit code of the container's last run.
Returns:
| Type | Description |
|---|---|
|
int or None: The exit code if available, otherwise None. |
Example
code = container.exit_code isinstance(code, int) or code is None True
image_name
property
Retrieve the full image name (including tag).
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The full image name. |
Example
container.image_name 'myapp:latest'
is_created
property
Check whether the container has been created.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the container exists, False otherwise. |
Example
container.is_created False
is_running
property
Check if the container is currently running.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if running, False otherwise. |
Example
container.is_running True
status
property
Get the current status of the container.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The container status. If not found, returns "removed". |
Example
status = container.status status in ["created", "running", "exited", "removed"] True
__init__(image, client=None)
Initialize a Container instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image
|
The Image object that provides the Docker image details. |
required |
client
|
Optional[DockerClient]
|
An optional Docker client instance. If not provided, docker.from_env() is used. |
None
|
Example
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 | |
create(config, tag=None)
Create a Docker container using the provided runtime configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
RuntimeConfig
|
The runtime configuration for the container. |
required |
tag
|
Optional[str]
|
An optional image tag override. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
|
None |
Example
container.create(runtime_config) container.is_created True
Source code in ures/docker/container.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | |
logs()
Retrieve logs from the container.
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
The log output from the container. |
Example
logs = container.logs() isinstance(logs, bytes) True
Source code in ures/docker/container.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
remove()
Remove the container.
Returns:
| Type | Description |
|---|---|
|
None |
Example
container.remove()
Source code in ures/docker/container.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
run()
Start the container if it has been created and is not already running.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the container has not been created or is already running. |
Returns:
| Type | Description |
|---|---|
|
None |
Example
container.run() container.is_running True
Source code in ures/docker/container.py
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | |
stop()
Stop the running container.
Returns:
| Type | Description |
|---|---|
|
None |
Example
container.stop()
Source code in ures/docker/container.py
289 290 291 292 293 294 295 296 297 298 299 300 301 | |
wait()
Wait for the container to finish execution.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
The container's exit information. |
Example
exit_info = container.wait() "StatusCode" in exit_info True
Source code in ures/docker/container.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | |
Image
Represents and manages a Docker image.
Attributes:
| Name | Type | Description |
|---|---|---|
_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. |
Source code in ures/docker/image.py
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 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 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 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 582 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 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 | |
architecture
property
Gets the architecture of the Docker image.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The image architecture (e.g., 'amd64'). |
Example
img = Image("myapp") img.architecture 'amd64'
exist
property
Checks if the image exists locally.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the image exists, False otherwise. |
Example
img = Image("myapp") img.exist # Depends on local Docker images
id
property
Gets the unique ID of the Docker image.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The Docker image ID. |
Example
img = Image("myapp") img.id 'sha256:...'
image
property
Gets the Docker image object.
Returns:
| Type | Description |
|---|---|
Optional[Image]
|
Optional[DockerImage]: The Docker image object if found, otherwise None. |
Example
img = Image("myapp") img.image # Might return a DockerImage object if available
image_size
property
Gets the size of the Docker image in bytes.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The size of the image in bytes. |
Example
img = Image("myapp") img.image_size 12345678
labels
property
Gets the labels of the Docker image.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A dictionary of image labels. |
Example
img = Image("myapp") img.labels {'version': '1.0'}
name
property
Gets the name of the image.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The image name. |
Example
img = Image("myapp") img.name 'myapp'
tag
property
Gets the tag of the image.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The image tag. |
Example
img = Image("myapp", tag="v1") img.tag 'v1'
__init__(image_name, tag=None, client=None)
Initializes an Image instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_name
|
str
|
The name of the Docker image. |
required |
tag
|
Optional[str]
|
The image tag. Defaults to "latest" if not provided. |
None
|
client
|
Optional[DockerClient]
|
The Docker client to use. Defaults to docker.from_env(). |
None
|
Example
img = Image("myapp", tag="v1")
Source code in ures/docker/image.py
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 | |
build_image(build_config, dest, build_context=None)
Builds a Docker image using the specified build configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
build_config
|
BuildConfig
|
The configuration for building the image. |
required |
dest
|
Union[str, Path]
|
The destination path where the Dockerfile will be saved. |
required |
build_context
|
Optional[Union[str, Path]]
|
The build context directory. Defaults to build_config.context_dir. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
DockerImage |
Image
|
The built Docker image. |
Example
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
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 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 610 611 612 613 614 615 616 617 618 619 620 | |
get_fullname(tag=None)
Constructs the full image name including the tag.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag
|
Optional[str]
|
The tag to use; if not provided, the instance's tag is used. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The full image name in the format "name:tag". |
Example
img = Image("myapp", tag="v1") img.get_fullname() 'myapp:v1'
Source code in ures/docker/image.py
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 | |
get_image(tag=None)
Retrieves the Docker image from the local repository.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag
|
Optional[str]
|
The tag to use when retrieving the image. Defaults to the instance's tag. |
None
|
Returns:
| Type | Description |
|---|---|
Optional[Image]
|
Optional[DockerImage]: The Docker image if found; otherwise, None. |
Example
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
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 | |
info()
Prints detailed information about the Docker image.
Returns:
| Type | Description |
|---|---|
|
None |
Example
img = Image("myapp") img.info()
Source code in ures/docker/image.py
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 | |
pull_image(tag=None)
Pulls the Docker image from a remote repository.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag
|
Optional[str]
|
The tag to pull; defaults to the instance's tag if not provided. |
None
|
Returns:
| Type | Description |
|---|---|
Optional[Image]
|
Optional[DockerImage]: The pulled Docker image if successful; otherwise, None. |
Example
img = Image("myapp") pulled = img.pull_image() pulled is not None
Source code in ures/docker/image.py
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 | |
remove(tag=None, force=False, noprune=False)
Removes the Docker image from the local repository.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag
|
Optional[str]
|
The tag to remove. Defaults to the instance's tag. |
None
|
force
|
bool
|
Force removal. Defaults to False. |
False
|
noprune
|
bool
|
Do not remove untagged parent images. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
|
None |
Example
img = Image("myapp") img.remove()
Source code in ures/docker/image.py
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 | |
ImageConstructor
Constructs a Dockerfile based on a provided build configuration.
This class generates Dockerfile content by appending commands derived from the build configuration and provides methods to save the generated Dockerfile.
Source code in ures/docker/image.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 | |
content
property
Retrieves the generated Dockerfile content as a list of command strings.
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: The Dockerfile content lines. |
Example
constructor = ImageConstructor(BuildConfig()) constructor.content # Might include commands like 'FROM python:3.10-slim'
home_dir
property
Returns the home directory path based on the configured user.
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
The home directory path (e.g. /home/{user} if user is specified, else /root). |
Example
from ures.docker.conf import BuildConfig config = BuildConfig(user="appuser") constructor = ImageConstructor(config) constructor.home_dir PosixPath('/home/appuser')
__init__(config)
Initializes the ImageConstructor with the given build configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
BuildConfig
|
The build configuration settings. |
required |
Returns:
| Type | Description |
|---|---|
|
None |
Example
from ures.docker.conf import BuildConfig config = BuildConfig(base_image="python:3.10-slim", user="appuser") constructor = ImageConstructor(config)
Source code in ures/docker/image.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
save(dest)
Saves the generated Dockerfile to the specified destination.
If the destination is a directory, the Dockerfile will be named using the configuration's docker_filename and placed inside that directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dest
|
Union[str, Path]
|
The destination file path or directory. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
The full path where the Dockerfile was saved. |
Example
constructor = ImageConstructor(BuildConfig(docker_filename="Dockerfile")) saved_path = constructor.save("/tmp") saved_path.name # Should be 'Dockerfile'
Source code in ures/docker/image.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
ImageOrchestrator
Orchestrates the building of multiple Docker images considering their dependencies.
Attributes:
| Name | Type | Description |
|---|---|---|
_client |
DockerClient
|
The Docker client instance. |
_images |
dict
|
A dictionary holding images and their build configuration and status. |
Source code in ures/docker/image.py
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 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 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 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 | |
images
property
Retrieves the dictionary of managed images.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Dict[str, Dict[str, Union[Optional[Image], BuildConfig, str]]]
|
A dictionary mapping image fullnames to their configuration and status. |
Example
orch = ImageOrchestrator() orch.images # Initially empty dictionary
__init__(client=None)
Initializes the ImageOrchestrator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Optional[DockerClient]
|
The Docker client instance. Defaults to docker.from_env(). |
None
|
Example
orchestrator = ImageOrchestrator()
Source code in ures/docker/image.py
683 684 685 686 687 688 689 690 691 692 693 694 695 696 | |
add_image(image, config, base=None)
Adds an image and its build configuration to the orchestrator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image
|
The Image instance to add. |
required |
config
|
BuildConfig
|
The build configuration for the image. |
required |
base
|
Image
|
The base image that this image depends on, if any. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
True if the image was added successfully. |
Example
orch = ImageOrchestrator() img = Image("myapp") config = BuildConfig() orch.add_image(img, config) True
Source code in ures/docker/image.py
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 | |
build_all()
Builds all registered images in the correct order based on dependencies.
Returns:
| Type | Description |
|---|---|
|
None |
Example
orchestrator.build_all()
Source code in ures/docker/image.py
789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 | |
BuildConfig
Bases: BaseModel
BuildConfig defines the build parameters for constructing a Docker image.
Attributes:
| Name | Type | Description |
|---|---|---|
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". |
Example
config = BuildConfig() config.base_image 'python:3.10-slim'
Source code in ures/docker/conf.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
add_copy(src, dest)
Add a file copy instruction to the build configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
str
|
Source file path. |
required |
dest
|
str
|
Destination path inside the container. |
required |
Returns:
| Type | Description |
|---|---|
|
None |
Example
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
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
add_environment(key, value)
Add an environment variable to the build configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The environment variable name. |
required |
value
|
str
|
The value for the environment variable. |
required |
Returns:
| Type | Description |
|---|---|
|
None |
Example
config = BuildConfig() config.add_environment("DEBUG", "true") config.environment["DEBUG"] 'true'
Source code in ures/docker/conf.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
add_label(key, value)
Add a label to the build configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The label key. |
required |
value
|
str
|
The label value. |
required |
Returns:
| Type | Description |
|---|---|
|
None |
Example
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 125 126 127 | |
add_python_dependency(dependency)
Add a Python dependency to be installed in the image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dependency
|
str
|
The Python package dependency (e.g., "flask==2.0.1"). |
required |
Returns:
| Type | Description |
|---|---|
|
None |
Example
config = BuildConfig() config.add_python_dependency("flask") "flask" in config.python_dependencies True
Source code in ures/docker/conf.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | |
add_run_command(command)
Add a command to be run during the build process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
The command to run (e.g., "apt-get update"). |
required |
Returns:
| Type | Description |
|---|---|
|
None |
Example
config = BuildConfig() config.add_run_command("apt-get update") "apt-get update" in config.run_commands True
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 261 262 | |
add_system_dependency(dependency)
Add a system dependency to be installed in the image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dependency
|
str
|
The system package dependency (e.g., "curl"). |
required |
Returns:
| Type | Description |
|---|---|
|
None |
Example
config = BuildConfig() config.add_system_dependency("curl") "curl" in config.sys_dependencies True
Source code in ures/docker/conf.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
set_cmd(cmd)
Set the command for the container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
Union[str, List[str]]
|
The command(s) to run. If a string is provided, it will be converted to a list. |
required |
Returns:
| Type | Description |
|---|---|
|
None |
Example
config = BuildConfig() config.set_cmd("python -m myapp") config.cmd ["python -m myapp"]
Source code in ures/docker/conf.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
set_context_dir(context_dir)
Set the build context directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context_dir
|
Union[str, Path]
|
The directory to be used as the build context. |
required |
Returns:
| Type | Description |
|---|---|
|
None |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the provided context directory does not exist or is not a directory. |
Example
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
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
set_entrypoint(entrypoint)
Set the entrypoint for the container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entrypoint
|
Union[str, List[str]]
|
The entrypoint command(s). If a string is provided, it will be converted to a list. |
required |
Returns:
| Type | Description |
|---|---|
|
None |
Example
config = BuildConfig() config.set_entrypoint("python app.py") config.entrypoint ["python app.py"]
Source code in ures/docker/conf.py
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | |
RuntimeConfig
Bases: BaseModel
RuntimeConfig defines the runtime parameters for running a Docker container.
Attributes:
| Name | Type | Description |
|---|---|---|
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. |
Example
config = RuntimeConfig() config.image_name 'model-runner'
Source code in ures/docker/conf.py
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 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 502 503 504 505 506 507 508 | |
cache
property
Get the cache directory within the output directory. If it does not exist, it is created.
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
The path to the cache directory. |
Example
config = RuntimeConfig() cache_directory = config.cache cache_directory.exists() True
log_dir
property
Get the log directory within the output directory. If it does not exist, it is created.
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
The path to the log directory. |
Example
config = RuntimeConfig() log_directory = config.log_dir log_directory.exists() True
add_env(key, value)
Add an environment variable for the container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The environment variable name. |
required |
value
|
str
|
The value for the environment variable. |
required |
Returns:
| Type | Description |
|---|---|
|
None |
Example
config = RuntimeConfig() config.add_env("DEBUG", "1") config.env["DEBUG"] '1'
Source code in ures/docker/conf.py
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 | |
add_volume(host_path, container_path, mode='rw')
Add a volume mapping for the container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host_path
|
Union[str, Path]
|
The path on the host machine. |
required |
container_path
|
Union[str, Path]
|
The destination path inside the container. |
required |
mode
|
str
|
The mode for the volume mapping (e.g., "rw" or "ro"). Defaults to "rw". |
'rw'
|
Returns:
| Type | Description |
|---|---|
|
None |
Example
config = RuntimeConfig() config.add_volume("/host/data", "/container/data", mode="rw") "/host/data" in config.volumes True
Source code in ures/docker/conf.py
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 | |