How do I publish a UDP Port on Docker?

DockerUdp

Docker Problem Overview


How do I forward a UDP port from my Docker container to the host machine?

Docker Solutions


Solution 1 - Docker

Use the -p flag and add /udp suffix to the port number.

-p 53160:53160/udp

Full command

sudo docker run -p 53160:53160 \
    -p 53160:53160/udp -p 58846:58846 \ 
    -p 8112:8112 -t -i aostanin/deluge /start.sh

If you're running boot2docker on Mac, be sure to forward the same ports on boot2docker to your local machine.

You can also document that your container needs to receive UDP using EXPOSE in The Dockerfile (EXPOSE does not publish the port):

EXPOSE 8285/udp

Here is a link with more Docker Networking info covered in the container docs: https://docs.docker.com/config/containers/container-networking/ (Courtesy of Old Pro in the comments)

Solution 2 - Docker

Just thought I would pitch in for docker-compose config.

ports:
  - "9955:9955/udp"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNick WoodhamsView Question on Stackoverflow
Solution 1 - DockerNick WoodhamsView Answer on Stackoverflow
Solution 2 - DockerFerdie De OliveiraView Answer on Stackoverflow