Skip to content

Commit

Permalink
Use host.docker.internal instead of local IP address in chrome.docker
Browse files Browse the repository at this point in the history
Resolves oblador#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.
  • Loading branch information
jamiepenney committed Jan 8, 2024
1 parent aac057d commit 2e8e084
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions packages/target-chrome-docker/src/create-chrome-docker-target.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,19 @@ function createChromeDockerTarget({
}
runArgs.push('--add-host=host.docker.internal:host-gateway');

if (dockerUrl.indexOf('http://localhost') === 0 || isLocalFile) {
const ip = getLocalIPAddress();
if (isLocalFile) {
let ip = 'host.docker.internal';
staticServerPort = getRandomPort();
staticServerPath = dockerUrl.substr('file:'.length);
dockerUrl = `http://${ip}:${staticServerPort}`;
} else if(dockerUrl.indexOf('http://localhost') === 0) {
let ip = getLocalIPAddress();
if (!ip) {
throw new Error(
'Unable to detect local IP address, try passing --host argument'
);
}
if (isLocalFile) {
staticServerPort = getRandomPort();
staticServerPath = dockerUrl.substr('file:'.length);
dockerUrl = `http://${ip}:${staticServerPort}`;
} else {
dockerUrl = dockerUrl.replace('localhost', ip);
}
dockerUrl = dockerUrl.replace('localhost', ip);
}

async function getIsImageDownloaded(imageName) {
Expand Down

0 comments on commit 2e8e084

Please sign in to comment.