mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 11:30:12 +08:00
Connect to different shell
This commit is contained in:
1 parent
4a74127785
commit
c83ca750e1
2 files changed
+29
-7
No files matched your search
@@ -22,6 +22,6 @@ export default (server) => {
|
|||||||
console.log('Disconnected from the client.')
|
console.log('Disconnected from the client.')
|
||||||
})
|
})
|
||||||
|
|
||||||
socket.send('Hello from server!')
|
socket.send(`${container.id}\n`)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -13,6 +13,20 @@ const containerOptions = {
|
|||||||
StdinOnce: false,
|
StdinOnce: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function createContainer() {
|
||||||
|
const container = await engine.createContainer({
|
||||||
|
...containerOptions,
|
||||||
|
})
|
||||||
|
await container.start()
|
||||||
|
return container
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getContainer(id) {
|
||||||
|
const container = await engine.getContainer(id)
|
||||||
|
await container.start()
|
||||||
|
return container
|
||||||
|
}
|
||||||
|
|
||||||
export async function getOrCreateContainer(name) {
|
export async function getOrCreateContainer(name) {
|
||||||
try {
|
try {
|
||||||
const container = engine.getContainer(name)
|
const container = engine.getContainer(name)
|
||||||
@@ -31,12 +45,20 @@ export async function getOrCreateContainer(name) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function attachContainer(container) {
|
export async function attachContainer(container) {
|
||||||
// Create an exec instance with bash shell
|
// Create an exec instance with bash shell
|
||||||
return container.attach({
|
const exec = await container.exec({
|
||||||
stream: true,
|
AttachStdin: true,
|
||||||
stdin: true,
|
AttachStdout: true,
|
||||||
stdout: true,
|
AttachStderr: true,
|
||||||
stderr: true,
|
Cmd: ['/bin/bash'],
|
||||||
|
Tty: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const execOutput = await exec.start({
|
||||||
|
Detach: false,
|
||||||
|
Tty: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
return execOutput.socket
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user