-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
fix(dx): configure devcontainer to use the host network #11640
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
Conversation
Add "--network=host" to tell docker to re-use the network connections of the host machine. Otherwise the host system can't reach the dev-server inside the devcontainer (what is the default on Windows+WSL2, in which case the browser spins forever loading localhost:3000).
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Can you please assume I don't know anything about devcontainers / Docker and tell me why this change improve things and how to test that you are right? (that's actually true, I did not write this config file) LLMs disagree with this PR 😅 |
|
I honestly don't know how to prove this to you. It took me more than an hour to figure it out the first time i came accross this issue, so i thought it could be handy for others too. According to the docker docs:
And the available network modes described here. Adding Links related to devcontainer setup describing this "workaround":
Asking AI depends how it was prompted 😉 GPT-4.1 Review### Prompt A pr was made to add the runArgs to a devcontainer to work properly for wsl too. Should i accept it? /* (code of the new devcontainer.json) */ResponseShort answer: Details: "runArgs": ["--network=host"]is a common practice to make networking (especially accessing host ports) work smoothly in WSL2 environments with Docker.
Risks/Considerations:
Bottom line: Action: Anyway, i'm fine adding this config for my local dev setup. |
In my experience, these kind of things are not to take so lightly. People using Docker expect the configs we provide to reduce risk by default. This new default would opt-out of one layer of security. In case of a vulnerability in our dev server (including transitive dependencies), this would likely expose the vulnerability more broadly. This already happened in the past ,see for example this RCE vulnerability in React Native dev server: GHSA-399j-vxmf-hjvr Since I'm not 100% sure about the risk of this change, so I'd rather not merge it. I understand it adds friction for some users, but I'd rather keep the friction and being more secure by default. This is also why we don't bind to If someone come up with a different solution that doesn't relax security, I'd be happy to consider it. |
Add
"--network=host"to tell docker to re-use the network connections of the host machine. Otherwise the host system can't reach the dev-server inside the devcontainer (what is the default on Windows+WSL2, in which case the browser spins forever loading localhost:3000).Motivation
Devcontainers are an easy way to get started with the project. The
--network=hostwas missing s.t. it did not work for a Windows+WSL setup.