Not able to understand how to communicate Docker container with SIP server residing in host layer

My HOST server and PBX Server are on the same LAN. Host server pings SIP server and vice versa.
My application which was on host server is moved to docker container now…
Now, am not able to make a connection from docker container application to the PBX sip server.

This is because the request generated from Docker container application contains the IP of the Docker container and not of the host server. We can port forward to the host layer but IP cannot change… SIP server is not able to ping the docker container

What can be the solution…

Sounds like you are not publishing the application’s listening port when you start the application’s container so the port is not available outside of Docker and the Application Docker container.
Check here for details -> https://docs.docker.com/config/containers/container-networking/

Port is exposed properly from the container, issue is with the IP …
i am exposing the port in my container and also forwarding the port to host as well. But the problem is with the IP… the SIP connection which i need is peer to peer . the SIP request packet which is forwarded from container to its host to the PBX SIP server contains the IP of the container and not the IP of the host. We cannot tamper the SIP request packet… So when PBX SIP server recieves the request and wants to ping back , it cannot understand the IP of the container and no communication here…

Okay. Is it possible for you to start the application docker container with host networking --network host?

1 Like

Yeah little naive here … can you share some examples where i can use the host network while connection… I did some example but could not understand what type of driver should i use when i create the docker network … will it be “overlay” or something else which we can communicate with the Host IP address rather and Host network devices.,
would really appreciate if you share some good content or examples …
Will try out those and will keep posted on my updates…

Sounds like you are using Docker Swarm. You did not elaborate.
Here’s an example with a Swarm docker-compose file Version 3.6 of running an Apache web server which is listening on port 80 in a docker container with host networking. No need to publish the port.

root@manager:~# cat docker-compose.yml
version: '3.6'

networks:
  hostnet:
     external: true
     name: "host"

services:
  web:
    image: httpd:latest
    networks:
      - hostnet
root@manager:~# docker stack deploy apache -c docker-compose.yml
Creating service apache_web
root@manager:~# curl 127.0.0.1
<html><body><h1>It works!</h1></body></html>
root@manager:~# hostname -I
10.0.2.15 172.28.128.3 172.17.0.1 172.18.0.1
root@manager:~#

I’m able to access the apache web server port from another host by the IP address of the docker node 172.28.128.3

🐳  gforghetti:[~] $ curl 172.28.128.3
<html><body><h1>It works!</h1></body></html>
🐳  gforghetti:[~] $
1 Like

Thanks so much for directing me to the correct usage of docker network. I am able to solve my issue by creating a “macvlan” driver for my docker network. I needed to give the Gateway of my host unix shell and by this way …my docker container can ping back any device which is on the HOST lan and ping is vice versa. The most important thing to take care is Allowing the Promiscuous mode on the host machine.