Wrong TCP source port in docker container

Viewed 112

Im running a docker container with asterisk inside. Asterisk is listening on port 5061 TCP, but in connects i see a different port in tcpdump.

docker run --log-driver none --name=asterisk-docker -dt --net=host --restart=always asterisk-docker

netstat output:

tcp        0      0 0.0.0.0:5061            0.0.0.0:*               LISTEN      58731/asterisk
tcp        0      0 srv-tk:46315            217.0.26.101:sip        ESTABLISHED

tcpdump output:

12:24:18.230394 IP 217.0.26.101.sip > srv-tk.46315: Flags [.], ack 3051, win 1217, options [nop,nop,TS val 391595046 ecr 3262544919], length 0
12:24:18.292636 IP 217.0.26.101.sip > srv-tk.46315: Flags [P.], seq 3444:4092, ack 3051, win 1217, options [nop,nop,TS val 391595061 ecr 3262544919], length 648

Why is this not 5061 as source/destination?

1 Answers

This is because behind docker networking is a lot of magic done with iptables. Packet forwarding, different networks layers, etc.

To check all this magic run this:

 sudo iptables -S

To see high layer layout of your containers execute the following command:

docker ps

If you want to understand high level docker networking I can recommend to read this documentation: https://docs.docker.com/network/

More about system networking behind docker network you can find here: https://argus-sec.com/docker-networking-behind-the-scenes/

Related