ccproxy.docker.protocol¶
ccproxy.docker.protocol
¶
Protocol definition for Docker operations.
DockerAdapterProtocol
¶
Bases: Protocol
Protocol for Docker operations.
is_available
¶
run
¶
run(
image,
volumes,
environment,
command=None,
middleware=None,
user_context=None,
entrypoint=None,
ports=None,
)
Run a Docker container with specified configuration.
Alias for run_container method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
str
|
Docker image name/tag to run |
required |
volumes
|
list[DockerVolume]
|
List of volume mounts (host_path, container_path) |
required |
environment
|
DockerEnv
|
Dictionary of environment variables |
required |
command
|
list[str] | None
|
Optional command to run in the container |
None
|
middleware
|
OutputMiddleware[T] | None
|
Optional middleware for processing output |
None
|
user_context
|
DockerUserContext | None
|
Optional user context for Docker --user flag |
None
|
entrypoint
|
str | None
|
Optional custom entrypoint to override the image's default |
None
|
ports
|
list[DockerPortSpec] | None
|
Optional port specifications (e.g., ["8080:80", "localhost:9000:9000"]) |
None
|
Returns:
Type | Description |
---|---|
Awaitable[ProcessResult[T]]
|
Tuple containing (return_code, stdout_lines, stderr_lines) |
Raises:
Type | Description |
---|---|
DockerError
|
If the container fails to run |
Source code in ccproxy/docker/protocol.py
run_container
¶
run_container(
image,
volumes,
environment,
command=None,
middleware=None,
user_context=None,
entrypoint=None,
ports=None,
)
Run a Docker container with specified configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
str
|
Docker image name/tag to run |
required |
volumes
|
list[DockerVolume]
|
List of volume mounts (host_path, container_path) |
required |
environment
|
DockerEnv
|
Dictionary of environment variables |
required |
command
|
list[str] | None
|
Optional command to run in the container |
None
|
middleware
|
OutputMiddleware[T] | None
|
Optional middleware for processing output |
None
|
user_context
|
DockerUserContext | None
|
Optional user context for Docker --user flag |
None
|
entrypoint
|
str | None
|
Optional custom entrypoint to override the image's default |
None
|
ports
|
list[DockerPortSpec] | None
|
Optional port specifications (e.g., ["8080:80", "localhost:9000:9000"]) |
None
|
Returns:
Type | Description |
---|---|
Awaitable[ProcessResult[T]]
|
Tuple containing (return_code, stdout_lines, stderr_lines) |
Raises:
Type | Description |
---|---|
DockerError
|
If the container fails to run |
Source code in ccproxy/docker/protocol.py
exec_container
¶
exec_container(
image,
volumes,
environment,
command=None,
user_context=None,
entrypoint=None,
ports=None,
)
Execute a Docker container by replacing the current process.
This method builds the Docker command and replaces the current process with the Docker command using os.execvp, effectively handing over control to Docker.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
str
|
Docker image name/tag to run |
required |
volumes
|
list[DockerVolume]
|
List of volume mounts (host_path, container_path) |
required |
environment
|
DockerEnv
|
Dictionary of environment variables |
required |
command
|
list[str] | None
|
Optional command to run in the container |
None
|
user_context
|
DockerUserContext | None
|
Optional user context for Docker --user flag |
None
|
entrypoint
|
str | None
|
Optional custom entrypoint to override the image's default |
None
|
ports
|
list[DockerPortSpec] | None
|
Optional port specifications (e.g., ["8080:80", "localhost:9000:9000"]) |
None
|
Raises:
Type | Description |
---|---|
DockerError
|
If the container fails to execute |
OSError
|
If the command cannot be executed |
Source code in ccproxy/docker/protocol.py
build_image
¶
Build a Docker image from a Dockerfile.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dockerfile_dir
|
Path
|
Directory containing the Dockerfile |
required |
image_name
|
str
|
Name to tag the built image with |
required |
image_tag
|
str
|
Tag to use for the image |
'latest'
|
no_cache
|
bool
|
Whether to use Docker's cache during build |
False
|
middleware
|
OutputMiddleware[T] | None
|
Optional middleware for processing output |
None
|
Returns:
Type | Description |
---|---|
Awaitable[ProcessResult[T]]
|
ProcessResult containing (return_code, stdout_lines, stderr_lines) |
Raises:
Type | Description |
---|---|
DockerError
|
If the image fails to build |
Source code in ccproxy/docker/protocol.py
image_exists
¶
Check if a Docker image exists locally.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_name
|
str
|
Name of the image to check |
required |
image_tag
|
str
|
Tag of the image to check |
'latest'
|
Returns:
Type | Description |
---|---|
Awaitable[bool]
|
True if the image exists locally, False otherwise |
Source code in ccproxy/docker/protocol.py
pull_image
¶
Pull a Docker image from registry.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_name
|
str
|
Name of the image to pull |
required |
image_tag
|
str
|
Tag of the image to pull |
'latest'
|
middleware
|
OutputMiddleware[T] | None
|
Optional middleware for processing output |
None
|
Returns:
Type | Description |
---|---|
Awaitable[ProcessResult[T]]
|
ProcessResult containing (return_code, stdout_lines, stderr_lines) |
Raises:
Type | Description |
---|---|
DockerError
|
If the image fails to pull |