gufo.thor.docker¶
Docker utilities.
Attributes:
| Name | Type | Description |
|---|---|---|
docker |
Docker singleton. |
ComposeConfig
dataclass
¶
Effective docker compose config.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Project name |
ContainerStatus
dataclass
¶
Container status.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Container name. |
Docker
¶
Docker wrapper.
compose_project_name
property
¶
Get compose project name.
logging_driver
cached
property
¶
Get docker logging driver.
Returns:
| Type | Description |
|---|---|
str
|
logging driver name. |
compose_exec(*args)
¶
Run a Compose exec command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
str
|
Arguments passed after |
()
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the command succeeds, otherwise False. |
destroy()
¶
Destroy installation.
Returns:
| Name | Type | Description |
|---|---|---|
True |
bool
|
if command executed successfully. |
False |
bool
|
otherwise. |
die(msg)
staticmethod
¶
Show error message and die.
docker_exec(*args)
¶
Execute docker command.
Replace current process with docker command.
Returns:
| Name | Type | Description |
|---|---|---|
True |
bool
|
if command executed successfully. |
False |
bool
|
otherwise. |
down(*args)
¶
Down services' containers.
Returns:
| Name | Type | Description |
|---|---|---|
True |
bool
|
if command executed successfully. |
False |
bool
|
otherwise. |
is_service_running(service)
¶
Check whether a Compose service has a running container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
service
|
str
|
Compose service name. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if at least one container for the service is running. |
logs(*args, _follow=False)
¶
Show logs.
pause(labels=None)
¶
Pause all containers having given labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
Iterable[str] | None
|
Iterable of all required labels. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
True |
bool
|
if command executed successfully. |
False |
bool
|
otherwise. |
pull()
¶
Pull containers.
Returns:
| Name | Type | Description |
|---|---|---|
True |
bool
|
if command executed successfully. |
False |
bool
|
otherwise. |
restart(*args)
¶
Perform services restart.
Returns:
| Name | Type | Description |
|---|---|---|
True |
bool
|
if command executed successfully. |
False |
bool
|
otherwise. |
run(*args)
¶
Run a Docker container and wait for it to exit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
str
|
Arguments passed after |
()
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the container exits successfully, otherwise False. |
shell()
¶
Run shell in container.
Returns:
| Name | Type | Description |
|---|---|---|
True |
bool
|
if command executed successfully. |
False |
bool
|
otherwise. |
stats()
¶
Show container stats.
Returns:
| Name | Type | Description |
|---|---|---|
True |
bool
|
if command executed successfully. |
False |
bool
|
otherwise. |
stop()
¶
Perform docker compose stop.
Returns:
| Name | Type | Description |
|---|---|---|
True |
bool
|
if command executed successfully. |
False |
bool
|
otherwise. |
unpause(labels=None)
¶
Resume all containers having given labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
Iterable[str] | None
|
Iterable of all required labels. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
True |
bool
|
if command executed successfully. |
False |
bool
|
otherwise. |
up()
¶
Perform docker compose up -d.
Returns:
| Name | Type | Description |
|---|---|---|
True |
bool
|
if command executed successfully. |
False |
bool
|
otherwise. |
with_paused(labels=None)
¶
Pause matching app containers for a context and resume them after.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
Iterable[str] | None
|
Additional container labels required for selection. |
None
|
Yields:
| Type | Description |
|---|---|
None
|
None. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If a container cannot be paused or resumed. |
with_started(services)
¶
Ensure Compose services are running for a context.
Services that were stopped on entry are started without starting their dependencies and stopped again on exit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
services
|
Iterable[str]
|
Compose service names to keep running in the context. |
required |
Yields:
| Type | Description |
|---|---|
None
|
None. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If a service cannot be started or stopped. |
DockerConfig
dataclass
¶
Docker daemon configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
logging_driver |
str
|
Current logging driver. |
server_version |
str
|
Current docker server version. |