mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +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.')
|
||||
})
|
||||
|
||||
socket.send('Hello from server!')
|
||||
socket.send(`${container.id}\n`)
|
||||
})
|
||||
}
|
||||
@@ -13,6 +13,20 @@ const containerOptions = {
|
||||
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) {
|
||||
try {
|
||||
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
|
||||
return container.attach({
|
||||
stream: true,
|
||||
stdin: true,
|
||||
stdout: true,
|
||||
stderr: true,
|
||||
const exec = await container.exec({
|
||||
AttachStdin: true,
|
||||
AttachStdout: true,
|
||||
AttachStderr: 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