Docker Community Forums

Share and learn in the Docker community.

Network Connection Between Swarm Cluster and Compose Service

swarm
docker

(Mayconfsbrito) #1

It’s possible to make an network connection between a docker compose service and a docker swarm container?

I’m trying to use traefik proxy outside of my docker swarm cluster to preserve the real IP (using X-Forwarded-For) from client-machines and pass these information to my app through docker network.

So, to do that I have the proxy on compose and my app on swarm.

I tried to use an overlay network between these, but didn’t work.

I have to do it because the issue #25526 (https://github.com/moby/moby/issues/25526)

Below these compose files to reproduce this example:

app compose file (whami):
version: ‘3’

services:
  whoami:
    image: emilevauge/whoami #A container that exposes an API to show it's IP address
    labels:
      - "traefik.backend=whoami"
      - "traefik.frontend.rule=Host:127.0.0.1"
      - "traefik.enable=true"
    deploy:
      replicas: 1
      restart_policy:
        condition: on-failure
        delay: 5s
        max_attempts: 3

Proxy (traefik) compose file:
version: ‘2’

services:
  reverse-proxy:
    image: traefik #The official Traefik docker image
    command: --api --docker #Enables the web UI and tells Træfik to listen to docker
    ports:
      - "80:80"     #The HTTP port
      - "8080:8080" #The Web UI (enabled by --api)
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock #So that Traefik can listen to the Docker events

(King Chung Huang) #2

The services can reach each other as long as they’re on a common network. Define a network and place both whoami and reverse-proxy in it.

See networks.