diff --git a/packages/techdocs-cli/src/commands/serve/serve.ts b/packages/techdocs-cli/src/commands/serve/serve.ts index 5fcf1787d3..328fcce607 100644 --- a/packages/techdocs-cli/src/commands/serve/serve.ts +++ b/packages/techdocs-cli/src/commands/serve/serve.ts @@ -24,6 +24,8 @@ import { LogFunc, waitForSignal } from '../../lib/run'; import { createLogger } from '../../lib/utility'; import { getMkdocsYml } from '@backstage/plugin-techdocs-node'; import fs from 'fs-extra'; +import { promisify } from 'util'; +import { execFile } from 'child_process'; function findPreviewBundlePath(): string { try { @@ -73,6 +75,23 @@ export default async function serve(opts: OptionValues) { mkdocsConfigFileName, }); + // Validate that Docker is up and running + if (opts.docker) { + logger.info('Checking Docker status...'); + try { + const runCheck = promisify(execFile); + await runCheck('docker', ['info'], { shell: true }); + logger.info( + 'Docker is up and running. Proceed to starting up mkdocs server', + ); + } catch { + logger.error( + 'Docker is not running. Exiting. Please check status of Docker daemon with `docker info` before re-running', + ); + return; + } + } + let mkdocsServerHasStarted = false; const mkdocsLogFunc: LogFunc = data => { // Sometimes the lines contain an unnecessary extra new line