mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 11:30:13 +08:00
Reuse container by name
This commit is contained in:
1 parent
e3d66709e4
commit
df12fee39c
2 files changed
+11
-7
No files matched your search
+9
-5
@@ -13,15 +13,19 @@ const containerOptions = {
|
||||
StdinOnce: false,
|
||||
}
|
||||
|
||||
export async function createContainer() {
|
||||
export async function getOrCreateContainer(name) {
|
||||
try {
|
||||
const container = await engine.createContainer(containerOptions)
|
||||
const container = engine.getContainer(name)
|
||||
await container.inspect()
|
||||
return container
|
||||
} catch (error) {
|
||||
const container = await engine.createContainer({
|
||||
...containerOptions,
|
||||
name,
|
||||
})
|
||||
await container.start()
|
||||
console.log(container.id)
|
||||
return container
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user