Access VS Code Dev Containers from your local network
Dominik Rüttiger 1 min read
There are two ways to publish ports to the host and make them available on the local network: Forwarding and publishing.
Forwarding
This is a
specific VS Code concept.
The idea is that forwarded ports look like localhost
to the container. That
makes it pretty easy to set up:
- Set
remote.localPortHost
in.vscode/settings.json
- Restart your server process in the container. For Astro, for example, this would be:
Publishing
This is just plain Docker:
- Set
appPort
in.devcontainer/devcontainer.json
: - Adjust the scripts in the
package.json
to make processes listen to all addresses. For Astro, for example, this would be: - Rebuild Dev Container
GitHub Codespaces
GitHub Codespaces does automatic forwarding for us, without the need to configure any of the settings mentioned above.
Browser support: If you are wondering why your application preview won’t show up in Chromium: It just does not work at the moment.
The officially supported browsers are Chrome, Edge, Firefox and Safari.
Tags
#astro #devcontainer #docker #dx #vscode