// Linux machines should use Docker's default gateway IP address to connect to.
let hostname = '172.17.0.1';

// On MacOS and Windows, `host.docker.internal` is available to point to the
// host and run backstopjs against.

// If the hostname arg is set, then we're inside the container and this should take precedence.
const hostArg = process.argv.find( ( arg ) => arg.match( /^--hostname=/ ) );

if ( hostArg ) {
	hostname = hostArg.replace( /^--hostname=/, '' );
} else if ( process.platform === 'darwin' || process.platform === 'win32' ) {
	hostname = 'host.docker.internal';
}

module.exports = hostname;

@@ -110,215 +110,121 @@
 %0A// 
-On MacOS and Windows, %60host.docker.internal%60 is available to point to the%0A// host and run backstopjs against.%0A%0A// If the hostname arg is set, then we're inside the container and this should take precedence.%0A
+If the moby arg is set, then backstop is running within a container.%0Aif ( process.argv.includes( '--moby' ) ) %7B%0A%09
 cons
@@ -299,26 +299,8 @@
 ) );
-%0A%0Aif ( hostArg ) %7B
 %0A%09ho
@@ -425,16 +425,100 @@
 32' ) %7B%0A
+%09// On MacOS and Windows, a dedicated hostname is available for resolving the host.%0A
 %09hostnam

Enhance detect-target-host logic.