Skip to content

Commit 444871c

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 a5130d1 commit 444871c

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

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

+7-8
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,19 @@ function createChromeDockerTarget({
4747
}
4848
runArgs.push('--add-host=host.docker.internal:host-gateway');
4949

50-
if (dockerUrl.indexOf('http://localhost') === 0 || isLocalFile) {
50+
if (isLocalFile) {
51+
const ip = 'host.docker.internal';
52+
staticServerPort = getRandomPort();
53+
staticServerPath = dockerUrl.substr('file:'.length);
54+
dockerUrl = `http://${ip}:${staticServerPort}`;
55+
} else if (dockerUrl.indexOf('http://localhost') === 0) {
5156
const ip = getLocalIPAddress();
5257
if (!ip) {
5358
throw new Error(
5459
'Unable to detect local IP address, try passing --host argument'
5560
);
5661
}
57-
if (isLocalFile) {
58-
staticServerPort = getRandomPort({ start: 1025 });
59-
staticServerPath = dockerUrl.substr('file:'.length);
60-
dockerUrl = `http://${ip}:${staticServerPort}`;
61-
} else {
62-
dockerUrl = dockerUrl.replace('localhost', ip);
63-
}
62+
dockerUrl = dockerUrl.replace('localhost', ip);
6463
}
6564

6665
async function getIsImageDownloaded(imageName) {

0 commit comments

Comments
 (0)