Skip to content

Purge unused/inactive local docker services #3768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/zenml/services/container/container_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from zenml.services.service import BaseService, ServiceConfig
from zenml.services.service_status import ServiceStatus
from zenml.utils import docker_utils
from zenml.utils.docker_utils import check_docker
from zenml.utils.io_utils import (
create_dir_recursive_if_not_exists,
get_global_config_directory,
Expand Down Expand Up @@ -217,6 +218,10 @@ def check_status(self) -> Tuple[ServiceState, str]:
providing additional information about that state (e.g. a
description of the error, if one is encountered).
"""
# Check if Docker is available first
if not check_docker():
return (ServiceState.INACTIVE, "Docker daemon is not running")

container: Optional[Container] = None
try:
container = self.docker_client.containers.get(self.container_id)
Expand Down
23 changes: 23 additions & 0 deletions src/zenml/zen_server/deploy/docker/docker_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# permissions and limitations under the License.
"""Zen Server docker deployer implementation."""

import os
import shutil
from typing import ClassVar, Optional, Tuple, Type, cast
from uuid import uuid4
Expand All @@ -30,6 +31,7 @@
ServiceEndpointHealthMonitorConfig,
ServiceEndpointProtocol,
)
from zenml.utils.docker_utils import check_docker
from zenml.zen_server.deploy.base_provider import BaseServerProvider
from zenml.zen_server.deploy.deployment import LocalServerDeploymentConfig
from zenml.zen_server.deploy.docker.docker_zen_server import (
Expand Down Expand Up @@ -253,6 +255,27 @@ def _get_service(self) -> BaseService:
Raises:
KeyError: If the server deployment is not found.
"""
# Check if Docker is available first
if not check_docker():
# Docker is not available, so we can't have a running Docker service
# Clean up the stale service configuration
service_config_path = DockerZenServer.config_path()
if os.path.exists(service_config_path):
logger.warning(
"Docker daemon is not running. Cleaning up stale Docker "
"ZenML server configuration at %s",
service_config_path,
)
try:
shutil.rmtree(service_config_path)
except Exception as e:
logger.debug(
"Failed to clean up stale Docker config: %s", e
)
raise KeyError(
"The docker ZenML server is not deployed (Docker daemon not running)."
)

service = DockerZenServer.get_service()
if service is None:
raise KeyError("The docker ZenML server is not deployed.")
Expand Down
Loading