Created
January 4, 2019 11:03
-
-
Save hongaar/d30fb88b937fe322b6a36f744c3e14a7 to your computer and use it in GitHub Desktop.
docker-proxy
This file contains hidden or 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 net = require('net') | |
const port = process.env['PORT'] || 5000 | |
function log (...args) { | |
// console.log(...args) | |
} | |
function onConnect (socket) { | |
log('new connection') | |
const upstream = net.connect('\\\\.\\pipe\\docker_engine') | |
upstream.on('connect', function () { | |
log('upstream connnected') | |
socket.resume() | |
}) | |
// Socket (HTTP connection) | |
socket.on('data', function (data) { | |
log('socket data:', data.length, 'bytes') | |
upstream.write(data) | |
}) | |
socket.on('end', function () { | |
log('socket end') | |
upstream.end() | |
}) | |
// Upstream (docker) | |
upstream.on('data', function (data) { | |
log('upstream data:', data.length, 'bytes') | |
socket.write(data) | |
}) | |
upstream.on('end', function () { | |
log('upstream end') | |
}) | |
} | |
net.createServer({ | |
allowHalfOpen: false, | |
pauseOnConnect: true | |
}, onConnect).listen(port) | |
console.log('listening on', port) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Workaround for issue with Docker Desktop for Windows: docker/for-win#3163