Created
July 25, 2019 20:21
-
-
Save totomz/0084b9eb1853eaf8545aaf6de57bf77d to your computer and use it in GitHub Desktop.
Sample js code to attach a running container using websocket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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