-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker.js
More file actions
29 lines (25 loc) · 848 Bytes
/
Copy pathdocker.js
File metadata and controls
29 lines (25 loc) · 848 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import Docker from 'dockerode'
import { CONFIG, configPath } from './util.js'
import path from 'path'
const docker = new Docker(CONFIG.docker_options ?? { version: 'v1.40' })
export async function create({ name, cmd, env, image, run }){
const container = await docker.createContainer({
name: name,
Image: image,
Cmd: cmd ? (cmd.match(/"([^"\\]|\\[^])+"|\S+/g)??[]).map(a => {
if(a[0] == '"') try{ return JSON.parse(a) }catch{}
return a
}) : undefined,
Env: env.split('\n').map(v => v.trim().split('#',1)[0]).filter(v => v),
AttachStdin: false,
AttachStdout: true,
AttachStderr: true,
HostConfig: {
Init: true,
Binds: [path.join(configPath, '..', name) + ':/data']
}
})
if(run) await container.start()
}
export const formatContainerId = str => str.toLowerCase().replace(/[^a-z0-9]/g, '-')
export default docker