Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker multiple networks routing #970

Closed
j0hnsmith opened this issue Dec 14, 2016 · 5 comments
Closed

docker multiple networks routing #970

j0hnsmith opened this issue Dec 14, 2016 · 5 comments

Comments

@j0hnsmith
Copy link
Contributor

j0hnsmith commented Dec 14, 2016

Here's an example docker-compose.yml that has two networks defined, one for containers that should have traefik config and one for those that shouldn't be exposed.

version: '2'

networks:
    traefik:
        driver: bridge
    backend:
        driver: bridge

services:
    traefik:
        image: traefik:v1.1.1
        command: --web --logLevel=DEBUG
        ports:
            - "80:80"
            - "8080:8080"
        volumes:
            - /var/run/docker.sock:/var/run/docker.sock
            - /dev/null:/traefik.toml
            - /root/acme.json:/acme.json
        networks:
            - traefik

    nginx:
        image: nginx:1.11.6-alpine
        expose:
            - "80"
        volumes:
            - /tmp:/usr/share/nginx/html
        labels:
            - "traefik.enable=true"
            - "traefik.backend=nginx"
            - "traefik.port=80"
            - "traefik.frontend.rule=PathPrefix:/"
        networks:
            - traefik

    backend_api:
        image: some_backend_api
        expose:
            - "8000"
        networks:
            - backend
            - traefik
        labels:
            - "traefik.enable=true"
            - "traefik.frontend.rule=PathPrefix:/api/"
            - "traefik.backend=backend_api"
            - "traefik.port=8000"
            - "traefik.passHostHeader=true"

    redis:
        image: redis:3.0.1
        mem_limit: 128M
        expose:
            - "6379"
        networks:
            - backend
        labels:
            - "traefik.enable=false"

    postgres:
        image: postgres:9.4.4
        environment:
            POSTGRES_PASSWORD: password
        expose:
            - "5432"
        networks:
            - backend
        labels:
            - "traefik.enable=false"

With a setup like this everything appears to be ok, but requests that match PathPrefix:/api/ timeout as traefik creates the backend with the ip from the backend network, not the one from the traefik network.

This is somewhat related to #959.

@MihaMarkic
Copy link

I'm seeing something similar. When multiple networks are used it won't route - time out. I have traefik in another docker-compose.

@MihaMarkic
Copy link

Actually there is "traefik.docker.network" setting. Did you try it?

@j0hnsmith
Copy link
Contributor Author

Ahh, yes. It works, thanks!

Note that if the network is created in a docker-compose.yml the actual name of the network is prefixed by the compose project name (run docker network ls to see the actual name).

Traefik could determine this itself making setting traefik.docker.network unnecessary.

@albjeremias
Copy link

Can you please post exactly how you solved this problem? Im having issues

@arnulfojr
Copy link

I'm having the same issue here, but I think I solve it by specifying the docker network in the traefik container's labels...
But could also use some sample of the final "solved" configuration

@traefik traefik locked and limited conversation to collaborators Sep 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants