-
Couldn't load subscription status.
- Fork 10.9k
Description
- 📖 DESCRIPTION
- ================================================================
- Universal Docker startup manager that eliminates the confusion
- between
docker compose(plugin-based) anddocker-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:
-
- Checks Docker installation
-
- Detects Compose variant
-
- Executes
up -dwith correct command
- Executes
-
- 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);
}