-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdocker-module.ts
More file actions
23 lines (19 loc) · 882 Bytes
/
docker-module.ts
File metadata and controls
23 lines (19 loc) · 882 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { IExecuteResult } from '../../instance/executor';
import { Unraid } from '../../instance/unraid';
import { Container } from './container';
import { RawContainer } from './docker.types';
export class DockerModule {
private readonly instance: Unraid;
constructor(instance: Unraid) {
this.instance = instance;
}
private async fetch(path: string): Promise<IExecuteResult> {
return this.instance.execute(`curl --unix-socket /var/run/docker.sock ${path}`);
}
async list(): Promise<Container[]> {
const { stdout, code } = await this.fetch('http://localhost/v1.41/containers/json?all=1');
if (code !== 0) throw new Error('Got non-zero exit code while listing containers');
const json: RawContainer[] = JSON.parse(stdout[0]);
return json.map((container) => new Container(this.instance, container));
}
}