Skip to content

Docker Compose Detection Failure on Mixed Environments #24650

@mohsinirfanpalla

Description

@mohsinirfanpalla
  • 📖 DESCRIPTION
  • ================================================================
  • Universal Docker startup manager that eliminates the confusion
  • between docker compose (plugin-based) and docker-compose (legacy binary).
  • Automatically detects the available command, verifies Docker,
  • and starts containers in detached mode.
  • Features:
  • • Cross-platform (macOS, Linux, Windows)
  • • Auto-detects Compose flavor
  • • Runs containers in detached mode
  • • Safe shell execution
  • • CI/CD-friendly logging
  • How it works:
    1. Checks Docker installation
    1. Detects Compose variant
    1. Executes up -d with correct command
    1. Logs status and exits gracefully
  • Use Cases:
  • • Local development automation
  • • CI pipelines
  • • Open-source repos needing fast container spin-up
  • Example:
  • ts-node scripts/start-docker.ts
  • node dist/scripts/start-docker.js
  • ================================================================

#!/usr/bin/env ts-node
import { execSync } from "child_process";

function tryExec(command: string): boolean {
try {
execSync(command, { stdio: "ignore", shell: true });
return true;
} catch {
return false;
}
}

function isDockerAvailable(): boolean {
return tryExec("docker --version");
}

function detectComposeType(): "plugin" | "legacy" | null {
if (tryExec("docker compose ls")) return "plugin";
if (tryExec("docker-compose version")) return "legacy";
return null;
}

function startContainers(): void {
if (!isDockerAvailable()) throw new Error("🚫 Docker is not installed or not found in PATH.");
const composeType = detectComposeType();
if (!composeType) throw new Error("🚫 Neither 'docker compose' nor 'docker-compose' is available.");
console.log("🐋 Docker detected!");
console.log(composeType === "plugin" ? "🧩 Using Docker Compose plugin..." : "⚙️ Using legacy docker-compose...");
const cmd = composeType === "plugin" ? "docker compose up -d" : "docker-compose up -d";
execSync(cmd, { stdio: "inherit", shell: true });
}

try {
console.log("🚀 Initializing Docker environment...");
startContainers();
console.log("✅ Containers started successfully!");
} catch (error) {
console.error(❌ Error: ${(error as Error).message});
process.exit(1);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐛 bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions