docker-exec-websocket-server
Purpose
A server that serves the results of docker exec over websockets.
See docker-exec-websocket-client
for a client that communicates with this server.
Usage
Server:
var DockerServer = require('../lib/server.js');
var dockerServer = new DockerServer({
port:8080,
server:
path: '/'+slugid.v4(),
containerId: 'servertest',
dockerSocket: '/var/run/docker.sock'
maxSessions: 10
});
await dockerServer.execute();
By default, uses /var/run/docker.sock
to communicate with Docker.
Message Types
Messages are prepended with a single byte which contains information about the encoded message. The payload is a Buffer
in node, or a UInt8Array
in browserify.
stdin: 0,
stdout: 1,
stderr: 2,
resume: 100,
pause: 101,
stopped: 200,
shutdown: 201,
error: 202
Testing
Ensure Docker is installed (docker -v
).
To test locally:
- Run
yarn install
to install the dependencies, including developer dependencies - Run
yarn test
- You can pass environment variables and commands to mocha as well, such as
DEBUG=* yarn test -f 'docker exec wc'
To test with docker-compose
, similar to CI:
- Run
docker-compose build --build-arg NODE_VERSION=16-bullseye
, or change to the desired
Node.js image tag - Run
docker-compose run --rm test
- Repeat
docker-compose build ...
when the code changes or you want to try a different Node.js image.