Dhaval Chaudhary
Dhaval Chaudhary

Reputation: 5815

Docker compose v3 specify network to be ingress?

I have docker-compose file for my docker swarm stack.I want my stack services to be deployed on specific network and that network i want to be ingress network so that i can use DNSRR of docker.

version: "3"
services:
 a:
  image: xyz/a:dev
  ports:
   - "80:80"
   - "443:443"
  networks:
   -my_network
b:
  image: xyz/b:dev
  ports:
  - "5000:5000"
  networks:
   -my_network

networks:
  my_network:
    driver:overlay
    ipam: 
     driver: default
     config:
       -subnet: 10.0.1.0/24

here, where can i specify that this network should be ingress network? plus how can i specify ip-range same as specified here in cli : here

Upvotes: 4

Views: 10382

Answers (3)

Rok Povsic
Rok Povsic

Reputation: 4925

Example of how to specify port ranges:

ports:
  - "9090-9091:8080-8081"

The long form allows specifying the mode as either host or ingress.

ports:
  - target: 80
    host_ip: 127.0.0.1
    published: 8080
    protocol: tcp
    mode: ingress

See the Ports section of the docker-compose spec for more details.

Upvotes: 1

Markus
Markus

Reputation: 3148

The ingress network is only for manager/worker nodes.

The routing mesh routes all incoming requests to published ports on available nodes to an active container. https://docs.docker.com/engine/swarm/ingress/

What you want is an addition overlay network. All services which are assigned to the same overlay network which is not ingress, can talk to each other over the name you've given them.

E.g.

docker service create --name A --network dev ...
docker service create --name B --network dev ...

Service A can simply do ping B.

Upvotes: 0

yamenk
yamenk

Reputation: 51778

Apparently, these options are not exposed in the composefile. The documentation doesn't mention them and to be sure you can check the source code, in particular the latest compose schema.

The only option is to create the ingress network on the command line and reference it from the compose file as an external network.

Upvotes: 3

Related Questions