Open gflarity opened 11 months ago
I just ran into something similar. When I debugged I saw requests being made to http://localhost instead of /var/run/docker.sock. Looks very similar to https://github.com/apocas/dockerode/issues/747
I am also hitting this. Is there any workaround?
I adapted the workaround proposed by https://github.com/apocas/dockerode/issues/747#issuecomment-1962746418
to use pure deno
and avoid the socat
dependency, it works in my own tools:
/******************************************************
* Begin workarounds for this showstopper issue:
* https://github.com/apocas/dockerode/issues/747
*/
async function startProxy() {
// Listen on TCP port 3000
const tcpListener = Deno.listen({ port: 3000 });
console.log("Listening on TCP port 3000");
for await (const tcpConn of tcpListener) {
handleConnection(tcpConn);
}
}
async function handleConnection(tcpConn: Deno.Conn) {
try {
// Connect to the Unix socket at /var/run/docker.sock
const unixConn = await Deno.connect({ transport: "unix", path: "/var/run/docker.sock" });
// Bidirectional forwarding
const tcpToUnix = copy(tcpConn, unixConn);
const unixToTcp = copy(unixConn, tcpConn);
// Wait for both copy operations to complete
await Promise.all([tcpToUnix, unixToTcp]);
} catch (error) {
console.error("Error handling connection:", error);
} finally {
tcpConn.close();
}
}
// Utility function to copy data from one stream to another
async function copy(src: Deno.Reader, dst: Deno.Writer) {
const buffer = new Uint8Array(1024);
while (true) {
const bytesRead = await src.read(buffer);
if (bytesRead === null) break;
let offset = 0;
while (offset < bytesRead) {
const bytesWritten = await dst.write(buffer.subarray(offset, bytesRead));
offset += bytesWritten;
}
}
}
// Start the proxy
startProxy();
// and this now needs to be changed because of the above:
// const docker = new Docker({socketPath: "/var/run/docker.sock"});
const docker = new Docker({protocol: 'http', host: 'localhost', port: 3000});
/******************************************************
* End workarounds for this showstopper issue:
* https://github.com/apocas/dockerode/issues/747
*/
The blog post said we should report, so here we go:
I just trying to use testcontainers (@testcontainers/postgresql) with Deno when I got this strange error:
So it seems there might be some http client compatibility issues, as the docker api is just HTTP last time I checked...
Here's the repro code which was inspired by this Testcontainer Node quickstart repo (which runs fine using node):