简体   繁体   中英

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?

It depends on how the container was run.
If it was with the -P (publish) option , that would map any EXPOSE'd port to a random host port.

Make sure to map at container runtime your port to a fixed port ( -p 1912:1812 : -p hostPort:ContainerPort ), and make sure to port-forward that in your VM Network setting as in " Connect to a Service running inside a docker container from outside ".

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM