Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use host.docker.internal instead of local IP address in chrome.docker #474

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
  • Loading branch information
jamiepenney committed Sep 2, 2024
commit 444871cfb2604a6ef8a41f6d6ba317b7e7ac42a7
15 changes: 7 additions & 8 deletions packages/target-chrome-docker/src/create-chrome-docker-target.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,19 @@ function createChromeDockerTarget({
}
runArgs.push('--add-host=host.docker.internal:host-gateway');

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