ssh-docker
A Sumor Cloud Tool.
More Documentation
ssh-docker is a docker tool for @sumor/ssh-tools
Installation
npm i @sumor/ssh-docker --save
Prerequisites
Node.JS version
Require Node.JS version 18.x or above
require Node.JS ES module
As this package is written in ES module,
please change the following code in your package.json
file:
{
"type": "module"
}
Usage
Import tool
import SSHBasic from '@sumor/ssh-tools'
import docker from '@sumor/ssh-docker'
class SSH extends SSHBasic {
constructor(config) {
super(config)
this.addTool('docker', docker)
}
}
export default SSH
Use tool
import SSH from './ssh.js'
const ssh = new SSH(server)
await ssh.connect()
const sourceFolder = '/path/to/source/folder'
const imageName = 'image-name'
const version = '1.0.0'
await ssh.docker.buildImage(sourceFolder, imageName, version)
const images = await ssh.docker.images()
const exists = await ssh.docker.existsImage(imageName, version)
await ssh.docker.run({
name: 'container-name',
image: imageName,
version: version,
ports: [
{
from: 443,
to: 30123
}
],
bindings: [
{
from: '/usr/source/config',
to: '/path/to/config/folder',
readOnly: true
}
]
})
const containers = await ssh.docker.containers()
const exists = await ssh.docker.exists('container-name')
const result = await ssh.docker.exec('container-name', 'ls -al')
await ssh.docker.remove('container-name')
await ssh.docker.removeImage(imageName, version)
const logs = await ssh.docker.buildNode('/path/to/source')
const logs = await ssh.docker.runNode('container-name', '/path/to/source', {
port
})
const logs = await ssh.docker.runNginx({
name: 'container-name',
ports: [
{
from: 443,
to: 30123
}
],
bindings: [
{
from: '/usr/source/config',
to: '/path/to/config/folder',
readOnly: true
}
]
})
await ssh.docker.updateNginx(dockerId)
await ssh.docker.runSite({
workerProcesses: 2,
workerConnections: 2048,
port: 30100,
domains: [
{
domain: 'dev.example.com',
servers: [
{
host: 'dev.example.com',
port: 30001,
maxFails: 3,
maxConns: 5
},
{
host: 'dev.example.com',
port: 30002,
weight: 1
}
]
}
]
})
await ssh.disconnect()