Windows 10 Docker Desktop on WSL2
Goal: serve an angular app from my devcontainer over my local network (specifically for testing on mobile)
Reproduce:
Things I've tried (and every permutation herein):
--network=host
(Never worked on windows, but thought it might on
WSL2 - doesn't)Additional Information:
ng serve --host 0.0.0.0
does
allow me to access the site over my network (but moving in and out of
the devcontainer isn't reasonable)My current DockerFile
is pretty vanilla:
ARG VARIANT="14-buster"
FROM mcr.microsoft.com/vscode/devcontainers/typescript-node:0-${VARIANT}
RUN npm install -g @angular/cli
RUN npm i yalc -g
My devcontainer.js
file is also unchanged (except for adding a volume)
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.187.0/containers/typescript-node
{
"name": "Node.js & TypeScript",
"build": {
"dockerfile": "Dockerfile",
"args": {
"VARIANT": "14"
}
},
"settings": {},
"extensions": [
"dbaeumer.vscode-eslint"
],
"remoteUser": "node",
"mounts": ["source=D:/GIT/docker/volumes/yalk,target=/yalc,type=bind,consistency=cached"],
}
you can accomplish this by modifying the option "appPort" inside devcontainer.js to this:
"appPort": ["4200:4200" ]
This way we are telling docker to "publish" port 4200 in our local network.
After this rebuild your devcontainer and the app should be accessible from phone by entering your IPv4:4200
You can find more info here in Dev Container metadata reference