Docker Community Forums

Share and learn in the Docker community.

Static ip address to connect different containers (MSSQL, CHATBOT, LETSENCRYPT)

We have setup three docker containers with docker-compose that run a MSSQL DB, a chatbot and a letsencrypt/NGINX container. It all works fairly well. The issue is, that if we re-run the docker-compose file that each of the three containers gets a different IP address.
Though - in each container we have config files that contain the ip address of one of the other containers - for example the chatbot container has a config file with the ip adress of the mssql database.
We are a little unclear what the best approach is to overcome this issue. We have read, that static ip addresses are not the best way in docker? What would be the best approach?

Thank you.

You can use the service name.

version: "3"
services:
 mssql:
   ...

 chatbot:
   ...
 
 letsencrypt:
   ...

These services can resolve eachother by these names, meaning from the chatbot container, you should be able to ping “mssql”, so you dont have to think about ips

1 Like

Before we can connect our assistant to messaging channels, we need to do some additional setup on the Rasa X server. As you recall, when we deployed Rasa X, we were able to access Rasa X in the browser by going to an IP address with an http protocol, like http://34.62.185.11/. That was fine while we were in early development, but in order to securely connect to external applications—our messaging channels—we need to configure a domain name and SSL. After completing these steps, the Rasa X server will be accessible at a secure, human-friendly URL like https://rasamasterclass.com.

First, we’ll assign a domain name to the server instance. Then, we can configure an SSL certificate, bound to the domain.

version: "3.2"
services:
  apache:
    image: ...
    networks:
      backend:
        ipv4_address: 172.20.1.5
  ...
  mysql:    
    networks:
      backend:
        ipv4_address: 172.20.1.2
networks:
  frontend:
  backend:
    ipam:
      config:
        - subnet: 172.20.1.0/24

And there you got two containers with fixed IP.

1 Like

Docker uses service discovery not need to have fixed IP

Thx for those hints - issue could be resolved!

It is funny to observe that docker beginners try to enforce old habits to the container world. With limited or no knowledge at all they draft a solution and try to forcefully apply it, no matter what…

At the same time subject matter experts like terpz provide the solution that actualy is needed… and it gets ignored because it is not the solution they understand… pitty.

At the end everyone is free to make as many mistakes as they want… No one can force you to do it right. Though, life is easier if you understand your tooling and use things how they are intended to be used…

1 Like