MCPcopy
hub / github.com/Dokploy/dokploy / getComposeContainer

Function getComposeContainer

packages/server/src/utils/docker/utils.ts:752–789  ·  view source on GitHub ↗
(
	compose: Compose,
	serviceName: string,
)

Source from the content-addressed store, hash-verified

750};
751
752export const getComposeContainer = async (
753 compose: Compose,
754 serviceName: string,
755) => {
756 try {
757 const { appName, composeType, serverId } = compose;
758 // 1. Determine the correct labels based on composeType
759 const labels: string[] = [];
760 if (composeType === "stack") {
761 // Labels for Docker Swarm stack services
762 labels.push(`com.docker.stack.namespace=${appName}`);
763 labels.push(`com.docker.swarm.service.name=${appName}_${serviceName}`);
764 } else {
765 // Labels for Docker Compose projects (default)
766 labels.push(`com.docker.compose.project=${appName}`);
767 labels.push(`com.docker.compose.service=${serviceName}`);
768 }
769 const filter = {
770 status: ["running"],
771 label: labels,
772 };
773
774 const remoteDocker = await getRemoteDocker(serverId);
775 const containers = await remoteDocker.listContainers({
776 filters: JSON.stringify(filter),
777 limit: 1,
778 });
779
780 if (containers.length === 0 || !containers[0]) {
781 return null;
782 }
783
784 const container = containers[0];
785 return container;
786 } catch (error) {
787 throw error;
788 }
789};
790
791type ServiceHealthStatus = {
792 status: "healthy" | "unhealthy";

Callers 2

runCommandFunction · 0.90
compose.tsFile · 0.90

Calls 1

getRemoteDockerFunction · 0.90

Tested by

no test coverage detected