mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
feat: seperate container creation and get
This commit is contained in:
1 parent
2c866d2e83
commit
8e63284211
3 files changed
+43
-19
No files matched your search
@@ -24,7 +24,16 @@ const containerOptions = {
|
||||
|
||||
const network = engine.getNetwork(config.dockerNetwork)
|
||||
|
||||
export async function getOrCreateContainer(id) {
|
||||
export async function createContainer(name) {
|
||||
const container = await engine.createContainer({
|
||||
...containerOptions,
|
||||
name,
|
||||
})
|
||||
await network.connect({ Container: container.id })
|
||||
return container
|
||||
}
|
||||
|
||||
export async function getAndStartContainer(id) {
|
||||
console.log(`Getting container: ${id}`)
|
||||
let container
|
||||
try {
|
||||
@@ -34,20 +43,7 @@ export async function getOrCreateContainer(id) {
|
||||
}
|
||||
return container
|
||||
} catch (error) {
|
||||
try {
|
||||
container = await engine.createContainer({
|
||||
...containerOptions,
|
||||
name: id,
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
await network.connect({ Container: container.id })
|
||||
|
||||
await container.start()
|
||||
console.log(container.id)
|
||||
return container
|
||||
throw new Error(`Container not found: ${id}`)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user