How do I forward a UDP port from my Docker container to the host machine?
Asked
Active
Viewed 1.4e+01k times
2 Answers
266
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)

andig
- 13,378
- 13
- 61
- 98

Nick Woodhams
- 11,977
- 10
- 50
- 52
-
4(rant) Literally nowhere in the official documentation, wow. "-p=[] : Publish a container᾿s port or a range of ports to the host format: ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort | containerPort". Although the official example mentions " -p 1234-1236:1234-1236/tcp", there are no matches for "udp" or "protocol" on the whole [page](https://docs.docker.com/engine/reference/run/#expose-incoming-ports). – Alexander Gonchiy Apr 03 '18 at 14:19
-
@AlexanderGonchiy Not to excuse the documentation for docker run, but the general format for exposing ports it is referring to is covered in the [Container Networking](https://docs.docker.com/config/containers/container-networking/) documentation. – Old Pro Sep 11 '18 at 01:21
-
2Expose should only be the port/proto, not a port pair like you have work publish. And expose does not publish the port and is not needed to publish the port, it's documentation. – BMitch Apr 22 '19 at 09:12
19
Just thought I would pitch in for docker-compose config.
ports:
- "9955:9955/udp"

Ferdie De Oliveira
- 461
- 4
- 10