Search code examples
macosdockerdocker-machinefreeradius

controlling docker-machine (using NAT) outgoing port


I have freeradius inside a docker container (in docker-machine on osx) that's sending a UDP packet on a particular port (1812). My logs inside the container show sending on 1812, but when I sniff the packet on the host (OSX) it's on some random UDP port.

Is there a way to control the outgoing port in docker-machine? ie -> container sends on 1812 also leaves the host on 1812.

Should I be using virtualbox port fowarding for this?


Solution

  • While I haven't been able to figure out how to force the source port for outgoing packets of docker-machine while running NAT mode. I did resolve my problem by adding a bridged adapter in virtualbox. This puts the docker-machine interface right on your LAN and it will get served an IP address. This removes NAT from the equation and the packets from the containers retain the outgoing source port.

    This virtualbox config can be done through the GUI or by running the following command.

    docker-machine stop <machine-name>
    VBoxManage modifyvm <machine-name> --nic3 bridged --bridgeadapter3 en0
    docker-machine start <machine-name>
    

    As VonC also stated you do need to publish the ports using the -p flag when running your docker container.