I am using Docker Swarm and stacks to deploy my services. Let's say that I have two services with following docker-compose files.
docker-compose-first.yml
version: "3.7"
services:
web:
image: first:1.0.0
networks:
- traefik-net
- notify-net
deploy:
replicas: 1
labels:
# enable Traefik for this service
- "traefik.enable=true"
- "traefik.docker.network=traefik-net"
# router
- "traefik.http.routers.first.rule=Host(`first.mydomain.com`)"
- "traefik.http.routers.first.entrypoints=application"
- "traefik.http.routers.first.tls=true"
- "traefik.http.routers.first.service=first"
# service
- "traefik.http.services.first.loadbalancer.server.port=443"
- "traefik.http.services.first.loadbalancer.server.scheme=https"
networks:
traefik-net:
external: true
name: traefik-net
notify-net:
external: true
name: notify-net
docker-compose-second.yml
version: "3.7"
services:
web:
image: second:1.0.0
networks:
- traefik-net
- notify-net
deploy:
replicas: 1
labels:
# enable Traefik for this service
- "traefik.enable=true"
- "traefik.docker.network=traefik-net"
# router
- "traefik.http.routers.second.rule=Host(`second.mydomain.com`)"
- "traefik.http.routers.second.entrypoints=application"
- "traefik.http.routers.second.tls=true"
- "traefik.http.routers.second.service=second"
# service
- "traefik.http.services.second.loadbalancer.server.port=443"
- "traefik.http.services.second.loadbalancer.server.scheme=https"
networks:
traefik-net:
external: true
name: traefik-net
notify-net:
external: true
name: notify-net
The files are almost the same, differences are in image name, host rule, router and service names. I deployed both stacks using:
docker stack deploy -c docker-compose-first.yml FirstService
docker stack deploy -c docker-compose-second.yml SecondService
Also, I created network notify-net
by running docker network create -d overlay --attachable notify-net
.
My question: How can I access https://second.mydomain.com:8081/RestApi/Test
from the first service (from inside the container)? I want the request to go through Traefik.