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