Skip to content

Commit 2e8e084

Browse files
committed
Use host.docker.internal instead of local IP address in chrome.docker
Resolves #473 Fixes an issue where the Chrome docker container cannot access Storybook running on the host machine via IP address, instead using the Docker `host.docker.internal` DNS entry to get access to it.
1 parent aac057d commit 2e8e084

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

packages/target-chrome-docker/src/create-chrome-docker-target.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,19 @@ function createChromeDockerTarget({
6666
}
6767
runArgs.push('--add-host=host.docker.internal:host-gateway');
6868

69-
if (dockerUrl.indexOf('http://localhost') === 0 || isLocalFile) {
70-
const ip = getLocalIPAddress();
69+
if (isLocalFile) {
70+
let ip = 'host.docker.internal';
71+
staticServerPort = getRandomPort();
72+
staticServerPath = dockerUrl.substr('file:'.length);
73+
dockerUrl = `http://${ip}:${staticServerPort}`;
74+
} else if(dockerUrl.indexOf('http://localhost') === 0) {
75+
let ip = getLocalIPAddress();
7176
if (!ip) {
7277
throw new Error(
7378
'Unable to detect local IP address, try passing --host argument'
7479
);
7580
}
76-
if (isLocalFile) {
77-
staticServerPort = getRandomPort();
78-
staticServerPath = dockerUrl.substr('file:'.length);
79-
dockerUrl = `http://${ip}:${staticServerPort}`;
80-
} else {
81-
dockerUrl = dockerUrl.replace('localhost', ip);
82-
}
81+
dockerUrl = dockerUrl.replace('localhost', ip);
8382
}
8483

8584
async function getIsImageDownloaded(imageName) {

0 commit comments

Comments
 (0)