Skip to content

Commit 1f03bad

Browse files
committedOct 12, 2022
fix: No HTTP_PROXY when connecting to Docker socket
CLIv2 sets up a global proxy where all traffic from the typescript modules / CLI parts are routed through a Go proxy. This is an issue for the Docker modem where we want to connect to Docker's socket directly, as the proxy alters the behaviour of the calls. Because traffic to a socket does not need a `host` or `port` to be set, the Go proxy that got that traffic re-routed it to `localhost:80`, which results in the CLI failing. I've opened an [upstream PR in the `global-agent`](gajus/global-agent#59) repo to not proxy traffic that should reach sockets in the first place. However, until this is fixed, we should simply use a custom agent for docker modem.
1 parent 64ec975 commit 1f03bad

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed
 

‎lib/docker.ts

+7
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ class Docker {
8181
);
8282

8383
const modem = new Modem();
84+
// Depending on how `DOCKER_HOST` is set, we might connect to a socket or an
85+
// HTTP server. However, the default http.globalAgent might be setup to use
86+
// HTTP_PROXY, which we do not want to do when connecting to a socket. As
87+
// such, if the socketPath is set, we do not use the global agent.
88+
if (modem.socketPath !== "") {
89+
modem.agent = false; // causes a new Agent with default values to be used.
90+
}
8491

8592
return new Promise<void>((resolve, reject) => {
8693
modem.dial(request, (err, stream: Stream) => {

0 commit comments

Comments
 (0)