Docker Community Forums

Share and learn in the Docker community.

Set static IP when using external network

docker

(Sanjibukai) #1

Hello,

I have some projects each having its own docker-compose.yml file.
For example I have 2 web sites (one static using nginx, one using rails).
I’m also using HAProxy as a reverse proxy.
For all these projects I defined an external network that I manually setup using docker network create haproxy_net.

In the HAProxy configuration file I should define the IP addresses of my services (I’m having trouble to use the hostnames).
After launching each project with its docker-compose up command, I’m able to inspect the containers to figure out what are the IP addresses.
Then, I change the HAProxy configuration file with those IP addresses.

In order to avoid to check and edit those addresses every time, I wanted to define static addresses (defined manually in the docker-compose.yml file of my services).
I thought to keep tracking those addresses in a .env file that I can then use in the docker-compose.yml file of my HAProxy project.
In fact it would be even better if I can defined the addresses once in the .env file and then use the environment variables even in the docker-compose.yml file of my services. But this probably require to share my .env file with all my dockers projects (is it possible to do that?)

The problem is that I got the error that user specified IP address is supported only when connecting to networks with user configured subnets

Is it really impossible to set static addresses when using an external network?