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:

  1. Set remote.localPortHost in .vscode/settings.json
    "remote.localPortHost": "allInterfaces"
    
  2. Reload the VS Code window

Publishing

This is just plain Docker:

  1. Set appPort in .devcontainer/devcontainer.json:
     "appPort": [
       "4321"
     ],
    
  2. Adjust the scripts in the package.json to make processes listen to all addresses. For Astro, for example, this would be:
    "start": "astro dev --host"
    
  3. 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

Share

Twitter LinkedIn Hacker News Reddit