mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
wip: allow connection from docker container
This commit is contained in:
1 parent
5ba0021c37
commit
4c292fd6ba
6 files changed
+36
-22
No files matched your search
@@ -4,45 +4,52 @@ import logger from '../utils/logger.js'
|
||||
|
||||
const engine = new Docker()
|
||||
|
||||
const containerOptions = {
|
||||
const newContainerOptions = (
|
||||
name: string,
|
||||
imageId: string,
|
||||
options: {
|
||||
binds?: string[]
|
||||
} = {}
|
||||
): Docker.ContainerCreateOptions => ({
|
||||
// AttachStdin: true,
|
||||
// AttachStdout: true,
|
||||
// AttachStderr: true,
|
||||
// Tty: true,
|
||||
// OpenStdin: true,
|
||||
// StdinOnce: false,
|
||||
name,
|
||||
Image: getQuestImage(imageId),
|
||||
HostConfig: {
|
||||
NetworkMode: config.docker.network,
|
||||
PortBindings: {
|
||||
'22/tcp': [
|
||||
{
|
||||
HostPort: '11122', // random port
|
||||
},
|
||||
],
|
||||
},
|
||||
NetworkMode: 'linux-odyssey-players', // config.docker.network,
|
||||
// PortBindings: {
|
||||
// '22/tcp': [
|
||||
// {
|
||||
// HostIP: '0.0.0.0',
|
||||
// HostPort: '11122', // random port
|
||||
// },
|
||||
// ],
|
||||
// },
|
||||
Binds: options.binds,
|
||||
ExtraHosts: ['host.docker.internal:host-gateway'],
|
||||
},
|
||||
ExposedPorts: {
|
||||
'22/tcp': {},
|
||||
// '22/tcp': {},
|
||||
},
|
||||
} as Docker.ContainerCreateOptions
|
||||
})
|
||||
|
||||
export function createContainer(
|
||||
name: string,
|
||||
imageId: string
|
||||
): Promise<Docker.Container> {
|
||||
const option = {
|
||||
...containerOptions,
|
||||
name,
|
||||
Image: getQuestImage(imageId),
|
||||
}
|
||||
|
||||
let binds: string[] = []
|
||||
if (!config.isProduction && config.docker.mountQuest && imageId !== 'base') {
|
||||
logger.info('Mounting quest folder', imageId)
|
||||
option.HostConfig!.Binds = [
|
||||
binds = [
|
||||
`${config.projectRoot}/quests/${imageId}/home:/home/commander`,
|
||||
`${config.projectRoot}/packages/container:/usr/local/lib/container`,
|
||||
]
|
||||
}
|
||||
const option = newContainerOptions(name, imageId, { binds })
|
||||
return engine.createContainer(option)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user