Skip to content

Commit 3f74f42

Browse files
committed
Revert "Use a custom hostname for Docker interception"
This reverts commit 08020b0. This breaks interception on Windows (and presumably Mac) because host.docker.internal is used as the target IP for the host mapping, and that's not an IP. We could use host-gateway, but that's not widely supported yet (Engine 20.10/API 1.41 only). Only a minor benefit, so just rolling this back for now, so we can use host.docker.internal everywhere and get maximum easy compatibility in the short term.
1 parent 303ea2e commit 3f74f42

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

src/interceptors/docker/docker-build-injection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
OVERRIDES_DIR
1414
} from '../terminal/terminal-env-overrides';
1515
import { getDeferred } from '../../util/promise';
16-
import { HTTP_TOOLKIT_DOCKER_HOSTNAME } from './docker-commands';
16+
import { DOCKER_HOST_HOSTNAME } from './docker-commands';
1717

1818
const HTTP_TOOLKIT_INJECTED_PATH = '/http-toolkit-injections';
1919
const HTTP_TOOLKIT_INJECTED_OVERRIDES_PATH = path.posix.join(HTTP_TOOLKIT_INJECTED_PATH, 'overrides');
@@ -46,7 +46,7 @@ export function injectIntoBuildStream(
4646
{ certPath: HTTP_TOOLKIT_INJECTED_CA_PATH },
4747
'runtime-inherit', // Dockerfile commands can reference vars directly
4848
{
49-
httpToolkitIp: HTTP_TOOLKIT_DOCKER_HOSTNAME,
49+
httpToolkitIp: DOCKER_HOST_HOSTNAME,
5050
overridePath: HTTP_TOOLKIT_INJECTED_OVERRIDES_PATH,
5151
targetPlatform: 'linux'
5252
}

src/interceptors/docker/docker-commands.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const HTTP_TOOLKIT_INJECTED_CA_PATH = path.posix.join(HTTP_TOOLKIT_INJECTED_PATH
3131
*
3232
* On Linux this is _not_ supported, so we add it ourselves with (--add-host).
3333
*/
34-
export const HTTP_TOOLKIT_DOCKER_HOSTNAME = "http-toolkit-host.docker.internal";
34+
export const DOCKER_HOST_HOSTNAME = "host.docker.internal";
3535

3636
/**
3737
* To make the above hostname work on Linux, where it's not supported by default, we need to map it to the
@@ -41,7 +41,7 @@ export const getDockerHostIp = (platform: typeof process.platform, dockerVersion
4141
if (platform !== 'linux') {
4242
// On non-linux platforms this method isn't necessary - host.docker.internal is always supported
4343
// so we can just use that.
44-
return "host.docker.internal";
44+
return DOCKER_HOST_HOSTNAME;
4545
} else if (dockerVersion &&
4646
semver.satisfies(semver.coerce(dockerVersion)?.version ?? '0.0.0', '>=1.21')
4747
) {
@@ -162,11 +162,17 @@ export function transformContainerCreationConfig(
162162
}
163163
: {}
164164
),
165-
ExtraHosts: [
166-
`${HTTP_TOOLKIT_DOCKER_HOSTNAME}:${proxyHost}`,
167-
// Seems that first host wins conflicts, so we go before existing values
168-
...(currentConfig.HostConfig?.ExtraHosts ?? [])
169-
]
165+
...(process.platform === 'linux'
166+
// On Linux only, we need to add an explicit host to make host.docker.internal work:
167+
? {
168+
ExtraHosts: [
169+
`${DOCKER_HOST_HOSTNAME}:${proxyHost}`,
170+
// Seems that first host wins conflicts, so we go before existing values
171+
...(currentConfig.HostConfig?.ExtraHosts ?? [])
172+
]
173+
}
174+
: {}
175+
)
170176
};
171177

172178
// Extend that config, injecting our custom overrides:
@@ -181,7 +187,7 @@ export function transformContainerCreationConfig(
181187
{ certPath: HTTP_TOOLKIT_INJECTED_CA_PATH },
182188
envArrayToObject(currentConfig.Env),
183189
{
184-
httpToolkitIp: HTTP_TOOLKIT_DOCKER_HOSTNAME,
190+
httpToolkitIp: DOCKER_HOST_HOSTNAME,
185191
overridePath: HTTP_TOOLKIT_INJECTED_OVERRIDES_PATH,
186192
targetPlatform: 'linux'
187193
}

src/interceptors/docker/docker-proxy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { addShutdownHandler } from '../../shutdown';
1717
import {
1818
isInterceptedContainer,
1919
transformContainerCreationConfig,
20-
HTTP_TOOLKIT_DOCKER_HOSTNAME,
20+
DOCKER_HOST_HOSTNAME,
2121
getDockerHostIp
2222
} from './docker-commands';
2323
import { injectIntoBuildStream, getBuildOutputPipeline } from './docker-build-injection';
@@ -247,7 +247,7 @@ async function createDockerProxy(proxyPort: number, httpsConfig: { certPath: str
247247
if (process.platform === 'linux') {
248248
reqUrl.searchParams.append(
249249
'extrahosts',
250-
`${HTTP_TOOLKIT_DOCKER_HOSTNAME}:${getDockerHostIp(process.platform, dockerVersion)}`
250+
`${DOCKER_HOST_HOSTNAME}:${getDockerHostIp(process.platform, dockerVersion)}`
251251
);
252252
req.url = reqUrl.toString();
253253
}

0 commit comments

Comments
 (0)