Skip to content

Commit 08020b0

Browse files
committed
Use a custom hostname for Docker interception
Shouldn't affect anything behaviourally, but makes some debugging clearer for end users I think.
1 parent ea88a08 commit 08020b0

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
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 { DOCKER_HOST_HOSTNAME } from './docker-commands';
16+
import { HTTP_TOOLKIT_DOCKER_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: DOCKER_HOST_HOSTNAME,
49+
httpToolkitIp: HTTP_TOOLKIT_DOCKER_HOSTNAME,
5050
overridePath: HTTP_TOOLKIT_INJECTED_OVERRIDES_PATH,
5151
targetPlatform: 'linux'
5252
}

src/interceptors/docker/docker-commands.ts

Lines changed: 8 additions & 14 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 DOCKER_HOST_HOSTNAME = "host.docker.internal";
34+
export const HTTP_TOOLKIT_DOCKER_HOSTNAME = "http-toolkit-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 DOCKER_HOST_HOSTNAME;
44+
return "host.docker.internal";
4545
} else if (dockerVersion &&
4646
semver.satisfies(semver.coerce(dockerVersion)?.version ?? '0.0.0', '>=1.21')
4747
) {
@@ -162,17 +162,11 @@ export function transformContainerCreationConfig(
162162
}
163163
: {}
164164
),
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-
)
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+
]
176170
};
177171

178172
// Extend that config, injecting our custom overrides:
@@ -187,7 +181,7 @@ export function transformContainerCreationConfig(
187181
{ certPath: HTTP_TOOLKIT_INJECTED_CA_PATH },
188182
envArrayToObject(currentConfig.Env),
189183
{
190-
httpToolkitIp: DOCKER_HOST_HOSTNAME,
184+
httpToolkitIp: HTTP_TOOLKIT_DOCKER_HOSTNAME,
191185
overridePath: HTTP_TOOLKIT_INJECTED_OVERRIDES_PATH,
192186
targetPlatform: 'linux'
193187
}

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-
DOCKER_HOST_HOSTNAME,
20+
HTTP_TOOLKIT_DOCKER_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-
`${DOCKER_HOST_HOSTNAME}:${getDockerHostIp(process.platform, dockerVersion)}`
250+
`${HTTP_TOOLKIT_DOCKER_HOSTNAME}:${getDockerHostIp(process.platform, dockerVersion)}`
251251
);
252252
req.url = reqUrl.toString();
253253
}

0 commit comments

Comments
 (0)