@@ -37,14 +37,28 @@ export const DOCKER_HOST_HOSTNAME = "host.docker.internal";
37
37
* To make the above hostname work on Linux, where it's not supported by default, we need to map it to the
38
38
* host ip. This method works out the host IP to use to do so.
39
39
*/
40
- export const getDockerHostIp = ( platform : typeof process . platform , dockerVersion : string | undefined , containerMetadata ?: Docker . ContainerInspectInfo ) => {
40
+ export const getDockerHostIp = (
41
+ platform : typeof process . platform ,
42
+ dockerVersion : { apiVersion : string } | { engineVersion : string } ,
43
+ containerMetadata ?: Docker . ContainerInspectInfo
44
+ ) => {
45
+ const semverVersion = semver . coerce (
46
+ 'apiVersion' in dockerVersion
47
+ ? dockerVersion . apiVersion
48
+ : dockerVersion . engineVersion
49
+ ) ;
50
+
41
51
if ( platform !== 'linux' ) {
42
52
// On non-linux platforms this method isn't necessary - host.docker.internal is always supported
43
53
// so we can just use that.
44
54
return DOCKER_HOST_HOSTNAME ;
45
- } else if ( dockerVersion &&
46
- semver . satisfies ( semver . coerce ( dockerVersion ) ?. version ?? '0.0.0' , '>=1.21' )
55
+ } else if (
56
+ semver . satisfies (
57
+ semverVersion ?? '0.0.0' ,
58
+ 'apiVersion' in dockerVersion ? '>=1.41' : '>=20.10'
59
+ )
47
60
) {
61
+ // This is supported in Docker Engine 20.10, so always supported at least in API 1.41+
48
62
// Special name defined in new Docker versions, that refers to the host gateway
49
63
return 'host-gateway' ;
50
64
} else if ( containerMetadata ) {
@@ -271,7 +285,7 @@ export async function restartAndInjectContainer(
271
285
272
286
const proxyHost = getDockerHostIp (
273
287
process . platform ,
274
- ( await docker . version ( ) ) . ApiVersion ,
288
+ { engineVersion : ( await docker . version ( ) ) . Version } ,
275
289
containerDetails
276
290
) ;
277
291
0 commit comments