Reputation: 4946
I want to use docker-compose with Docker Swarm (I use docker version 1.13 and compose with version: '3'
syntax).
Is each service reachable as a "single" service to the other services? Here is an simplified example to be clear:
version: '3'
services:
nodejs:
image: mynodeapp
container_name: my_app
ports:
- "80:8080"
environment:
- REDIS_HOST=my_redis
- REDIS_PORT=6379
deploy:
mode: replicated
replicas: 3
networks:
- my_net
command: npm start
redis:
image: redis
container_name: my_redis
restart: always
expose:
- 6379
deploy:
mode: replicated
replicas: 2
networks:
- my_net
networks:
my_net:
external: true
Let's say I have 3 VMs which are configured as a swarm. So there is one nodejs container running on each VM but there are only two redis container.
On the VM where no redis is running: Will my nodejs container know about the redis?
Addiitonal questions:
When I set replicas: 4
for my redis, I will have two redis container on one VM: Will this be a problem for my nodejs app?
Last question:
When I set replicas: 4
for my nodeapp: Will this even work because I now have exposed two times port 80?
Upvotes: 0
Views: 636
Reputation: 11
The services have to be stateless. In the case of databases it is necessary to set the cluster mode in each instance, since they are statefull.
Upvotes: 1
Reputation: 871
In the same order you asked:
Upvotes: 0