@@ -37,14 +37,28 @@ export const DOCKER_HOST_HOSTNAME = "host.docker.internal";
3737 * To make the above hostname work on Linux, where it's not supported by default, we need to map it to the
3838 * host ip. This method works out the host IP to use to do so.
3939 */
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+
4151 if ( platform !== 'linux' ) {
4252 // On non-linux platforms this method isn't necessary - host.docker.internal is always supported
4353 // so we can just use that.
4454 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+ )
4760 ) {
61+ // This is supported in Docker Engine 20.10, so always supported at least in API 1.41+
4862 // Special name defined in new Docker versions, that refers to the host gateway
4963 return 'host-gateway' ;
5064 } else if ( containerMetadata ) {
@@ -271,7 +285,7 @@ export async function restartAndInjectContainer(
271285
272286 const proxyHost = getDockerHostIp (
273287 process . platform ,
274- ( await docker . version ( ) ) . ApiVersion ,
288+ { engineVersion : ( await docker . version ( ) ) . Version } ,
275289 containerDetails
276290 ) ;
277291
0 commit comments