Class ContainerService
Provides operations to list, start, stop, restart, and update containers as well as to retrieve and stream container logs. All mutating operations (stop, restart, update) enforce the configured container blacklist before proceeding.
The update operation performs a full container replacement: it pulls the latest image, removes the existing container, recreates it with the original configuration (environment variables, labels, ports, volumes, networks, health check), and starts the new container.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancheckForUpdate(String imageName) Checks whether a newer version of the given image is available in the remote registry.getContainerLogs(String containerId, int tailLines) Retrieves historical container logs (non-streaming).listContainers(boolean showAll) Lists Docker containers, optionally including stopped containers.voidrestartContainer(String containerId) Restarts a container after verifying it is not blacklisted.voidstartContainer(String containerId) Starts a stopped container.voidstopContainer(String containerId) Stops a container after verifying it is not blacklisted.io.smallrye.mutiny.Multi<String> streamContainerLogs(String containerId, boolean follow) Streams container log output as a reactiveMulti.voidupdateContainer(String containerId) Performs a full container update by pulling the latest image and recreating the container.
-
Constructor Details
-
ContainerService
public ContainerService()
-
-
Method Details
-
listContainers
Lists Docker containers, optionally including stopped containers.- Parameters:
showAll- iftrue, includes containers in all states; otherwise only running- Returns:
- a list of container summary DTOs
-
restartContainer
Restarts a container after verifying it is not blacklisted.- Parameters:
containerId- the Docker container identifier- Throws:
ServiceBlacklistedException- if the container is blacklisted
-
stopContainer
Stops a container after verifying it is not blacklisted.- Parameters:
containerId- the Docker container identifier- Throws:
ServiceBlacklistedException- if the container is blacklisted
-
startContainer
Starts a stopped container.- Parameters:
containerId- the Docker container identifier
-
checkForUpdate
Checks whether a newer version of the given image is available in the remote registry.Compares the local image identifier with the identifier obtained after pulling the latest tag. Returns
trueif the identifiers differ, indicating an update is available.- Parameters:
imageName- the image reference to check (including tag)- Returns:
trueif a newer image is available in the registry
-
updateContainer
Performs a full container update by pulling the latest image and recreating the container.The update sequence is: pull latest image, stop the existing container, capture its network connections, remove it, create a new container preserving the original configuration (environment, labels, ports, volumes, entrypoint, health check, host config), reconnect additional networks, and start the new container.
- Parameters:
containerId- the Docker container identifier- Throws:
ServiceBlacklistedException- if the container is blacklistedRuntimeException- if the update is interrupted or fails
-
streamContainerLogs
Streams container log output as a reactiveMulti.Attaches to the container's stdout and stderr with timestamps enabled. The underlying Docker log callback is closed automatically when the stream terminates.
- Parameters:
containerId- the Docker container identifierfollow- iftrue, the stream follows new output (similar totail -f)- Returns:
- a reactive stream of log lines
-
getContainerLogs
Retrieves historical container logs (non-streaming).- Parameters:
containerId- the Docker container identifiertailLines- the maximum number of trailing log lines to return- Returns:
- the concatenated log output, or an error message if retrieval is interrupted
-