0

I have a docker container that services UDP packets and which needs to be on a static address.

I used the following commands:

docker network create --subnet=172.18.0.0/16 mynet123

docker run --net mynet123 --ip 172.18.0.22 -it ubuntu myservice

However I'm not receiving the UDP packets I expect to. I wonder if I need to specify that the UDP port I'm using should be open, however I can't find out how to do this. The documentation talks about the -p option for mapping port from the host to the container which is very much not what I want.

The standard approach of assigning my host the static address and using the -p option to map the port to the container does not work for me, this is because the service looks at the from address of the UDP packet to identify it and that's always the address of the host when you port forward. However I did actually receive the UDP packets when I follow this approach.

trampster
  • 8,598
  • 4
  • 37
  • 52
  • Where are you trying to get to the 172.18.0.22 address from? A user defined network container address is normally only available from the host the docker daemon is running on. – Matt Mar 09 '18 at 06:16
  • The address is a static IP Address allocated and assigned for this use by our IT department. – trampster Mar 09 '18 at 06:52
  • The container starts and is able to query rest API's for other devices on our system. It just doesn't get any UDP packets sent to it. It also has the correct address confirmed via ip addr show. – trampster Mar 09 '18 at 06:54
  • So what I've created is a container that has a static address which can't be accessed outside of the host. Is there anyway to have a publicly accessible static IP Address, the UDP protocol that this services needs the from UDP address to be the address of the actual sender, forwarding will not work. Or is docker actually not fit for this purpose. – trampster Mar 09 '18 at 07:22
  • It can work. See here for a subnet routing setup: https://stackoverflow.com/a/42240738/1318694 if your IT department can setup a route for the subnet to your Docker host. It can be a lot smaller than 172.18.0.0/16. – Matt Mar 09 '18 at 08:23
  • If your stuck with the single IP address, and it needs to appear on the network then you can use the [macvlan network driver](https://docs.docker.com/network/macvlan/) – Matt Mar 09 '18 at 08:26
  • You can also put the main interface of the Docker host on a bridge, and attach the containers to that bridge so it's directly on your network. https://stackoverflow.com/a/43244221/1318694 – Matt Mar 09 '18 at 08:28

0 Answers0