Overview
TheContainerize class is a Python decorator that automatically builds, packages, and runs your application in a container. When applied to a function, it handles all the containerization steps including Dockerfile generation, image building, and container execution.
Constructor
Parameters
Runtime configuration options. See RuntimeOptions for available fields.
Package configuration options. See PackageOptions for available fields.
Usage
Basic Example
With Publishing
Behavior
When the decorated function is called:- Container Detection: Checks if already running inside a container
- Direct Execution: If in container, executes the wrapped function directly
- Containerization: If not in container:
- Generates a Dockerfile (or uses custom dockerfile if provided)
- Builds the container image
- Publishes the image if
publish=True - Runs the container using the configured executor
- Returns container logs
Methods
__call__(func)
Makes the class instance callable as a decorator.The function to containerize
Properties
image
The full image name constructed from package repository and name. Format:{repository}/{name}:latest
builder
The selected builder instance based onpackage.builder configuration.
runner
The selected runner instance based onruntime.executor configuration.
Signal Handling
The decorator automatically handlesSIGINT (Ctrl+C) by:
- Canceling the running container
- Cleaning up resources
- Exiting gracefully
Custom Dockerfiles
You can provide a custom Dockerfile by setting thedockerfile parameter in PackageOptions:
py_version.