Skip to content

Instantly share code, notes, and snippets.

@totomz
Created July 25, 2019 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save totomz/0084b9eb1853eaf8545aaf6de57bf77d to your computer and use it in GitHub Desktop.
Save totomz/0084b9eb1853eaf8545aaf6de57bf77d to your computer and use it in GitHub Desktop.
Sample js code to attach a running container using websocket
const WebSocket = require('ws');
const id = '81bf9a17d914';
const url = `ws+unix:///var/run/docker.sock:/containers/${id}/attach/ws?stream=1&stdout=1&logs=1`;
const socket = new WebSocket(url, {
perMessageDeflate: false
});
socket.on('open', function (event) {
console.log("bomba");
});
// Listen for messages
socket.on('message', function (event) {
console.log('Message from server ', event); // Event is a Buffer<>
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment