How to forward a UDP port from a devcontainer?

Viewed 1402

I'm trying to use the "Node.js & Mongo DB" devcontainer from Microsoft (https://github.com/microsoft/vscode-dev-containers/tree/main/containers/javascript-node-mongo/.devcontainer) with my udp server made in Nodejs.

The problem is as follows: When i try to forward a port in devcontainer.json example : "forwardPorts": [1117].

It seems to only forward 1117/tcp when i actually want to forward 1117/udp.

I'm trying to making this work for this project : https://github.com/QuentinGruber/h1z1-server/blob/master/.devcontainer/devcontainer.json

2 Answers

The documentation is kinda fuzzy regarding protocols used for exposed ports with forwardPorts tag:

forwardPorts

  • array
  • An array of ports that should be forwarded from inside the container to the local machine.

Because of that I would recommend trying to use the older appPort tag because when I looked here it said they're using the docker-compose syntax which means you can specify the ports and protocol like so:

docker-compose:

ports:
- "3000"
- "8921:5000"

devcontainers.json:

"appPort": [ 3000, "8921:5000" ]

And in your case:

"appPort": [ "1117:1117/udp" ]

According to the docs, using the appPort tag is also useful when you want to access the application (or expose the ports) to more than just localhost

Fllowing the documentation you can forward udp protocol with this line

docker run -p 53160:53160/udp docker/getting-started

So trying add this to your configuration file and should works.

References: docker network

Related