Skip to content

Commit a14ead6

Browse files
committed
docker: isDaemonRunning func
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
1 parent f9de623 commit a14ead6

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

__tests__/docker/docker.test.itg.ts

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ import {Docker} from '../../src/docker/docker';
2020

2121
const maybe = !process.env.GITHUB_ACTIONS || (process.env.GITHUB_ACTIONS === 'true' && process.env.ImageOS && process.env.ImageOS.startsWith('ubuntu')) ? describe : describe.skip;
2222

23+
maybe('isDaemonRunning', () => {
24+
it('checks if daemon is running', async () => {
25+
expect(await Docker.isDaemonRunning()).toBe(true);
26+
});
27+
});
28+
2329
maybe('pull', () => {
2430
// prettier-ignore
2531
test.each([

src/docker/docker.ts

+11
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ export class Docker {
5454
});
5555
}
5656

57+
public static async isDaemonRunning(): Promise<boolean> {
58+
try {
59+
await Docker.getExecOutput([`version`], {
60+
silent: true
61+
});
62+
return true;
63+
} catch (e) {
64+
return false;
65+
}
66+
}
67+
5768
public static async exec(args?: string[], options?: ExecOptions): Promise<number> {
5869
return Exec.exec('docker', args, Docker.execOptions(options));
5970
}

0 commit comments

Comments
 (0)