Docker Community Forums

Share and learn in the Docker community.

Static IP in a external network on docker-compose


(Jaume) #1

Hello,

I have a docker-compose only for a nginx-proxy. This compose creates all the networks and upstreams for the apps that it serves (one different compose and network for each app).
The idea is having the proxy always up regardless the apps that I start when I want.
In the nginx configuration I use

upstream upstream_proxy-ncloud {
     server 10.11.12.13:80 max_fails=0;
}    

because if I put a DNS name, nginx fails to start because it can’t resolve the DNS name :disappointed_relieved:. So, I need to fix the static IP 10.11.12.13 in the docker-compose.yml file. I am doing this with ipv4 directive but it seems that this is not working because docker always assign a random IP. This is my docker-compose:

PROXY

services:
  nginxproxy:
    image: nginx
  network:
    - net1
networks:
  net1:
    attachable: true
    ipam:
     config:
     - subnet: 10.11.12.0/24

APP

services:
  app1:
    image: app1
   networks:
      proxy_net1:
        ipv4_address: 10.11.12.35
networks:
  proxy_net1:
    external: true

It never assigns 10.11.12.35 adress :frowning:
For the moment, I can only do this starting first all the apps and finally the proxy but, this behavior is not what I need.
I read some docker nginx-proxy projects in docker hub that autodiscover the apps I think but, for me they are very complicated and I am searching for a less complicated solution if it is possible.

If I try this in the command line, it works:
docker run --rm -ti --ip 10.11.12.23 --net proxy_net1 alpine:3.5

Does anyone know a way to do it in docker-compose?

Version:       18.01.0-ce
API version:   1.35
Go version:    go1.9.2
Git commit:    03596f51b1
Built: Sun Jan 14 23:10:39 2018
OS/Arch:       linux/amd64
Experimental:  false
Orchestrator:  swarm
Server:
Engine:
Version:      18.01.0-ce
API version:  1.35 (minimum version 1.12)
Go version:   go1.9.2
Git commit:   03596f51b1
Built:        Sun Jan 14 23:11:14 2018
OS/Arch:      linux/amd64
Experimental: false

Thanks in advance