LumenAlbum
LumenAlbum

Reputation: 165

Traefik 2 network between 2 containers results in Gateway Timeout errors

I'm trying to set up 2 docker containers with docker-compose, 1 is a Traefik proxy and the other is a Vikunja kanban board container. They both have their own docker-compose file. I can start the containers and the Traefik dashboard doesn't show any issues but when I open the URL in a browser I only get a Gateway Timeout error.

I have been looking at similar questions on here and different platforms and in nearly all other cases the issue was that they were placed on 2 different networks. However, I added a networks directive to the Traefik docker-compose.yml and still have this problem, unless I'm using them wrong.

The docker-compose file for the Vikunja container (adapted from https://vikunja.io/docs/full-docker-example/)

version: '3'

services:
  api:
    image: vikunja/api
    environment:
      VIKUNJA_DATABASE_HOST: db
      VIKUNJA_DATABASE_PASSWORD: REDACTED
      VIKUNJA_DATABASE_TYPE: mysql
      VIKUNJA_DATABASE_USER: vikunja
      VIKUNJA_DATABASE_DATABASE: vikunja
      VIKUNJA_SERVICE_JWTSECRET: REDACTED
      VIKUNJA_SERVICE_FRONTENDURL: REDACTED
    volumes:
      - ./files:/app/vikunja/files
    networks:
      - web
      - default
    depends_on:
      - db
    restart: unless-stopped
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.vikunja-api.rule=Host(`subdomain.domain.de`) && PathPrefix(`/api/v1`, `/dav/`, `/.well-known/`)"
      - "traefik.http.routers.vikunja-api.entrypoints=websecure"
      - "traefik.http.routers.vikunja-api.tls.certResolver=myresolver"
  frontend:
    image: vikunja/frontend
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.vikunja-frontend.rule=Host(`subdomain.domain.de`)"
      - "traefik.http.routers.vikunja-frontend.entrypoints=websecure"
      - "traefik.http.routers.vikunja-frontend.tls.certResolver=myresolver"
    networks:
      - web
      - default
    restart: unless-stopped
  db:
    image: mariadb:10
    command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    environment:
      MYSQL_ROOT_PASSWORD: REDACTED
      MYSQL_USER: vikunja
      MYSQL_PASSWORD: REDACTED
      MYSQL_DATABASE: vikunja
    volumes:
      - ./db:/var/lib/mysql
    restart: unless-stopped
    command: --max-connections=1000
    networks:
      - web

networks:
  web:
    external: true

The network directives for the api and frontend services in the Vikunja docker-compose.yml were present in the template (I added one for the db service for testing but it didn't have any effect).

networks:
      - web

After getting a docker error about the network not being found I created it via docker network create web

The docker-compose file for the Traefik container

version: '3'

services:
  traefik:
    image: traefik:v2.8
    ports:
      - "80:80"
      - "443:443"
      - "8080:8080" # dashboard
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./letsencrypt:/letsencrypt
      - ./traefik.http.yml:/etc/traefik/traefik.yml
    networks:
      - web

networks:
  web:
    external: true

I've tried adding the Traefik service to the Vikunja docker-compose.yml in one file but that didn't have any effect either.

I'm thankful for any pointers.

Upvotes: 1

Views: 1021

Answers (3)

Julian
Julian

Reputation: 427

I had the same problem, but now I found a solution. You need to add network_mode to your docker-compose.yml:

services:
  traefik:
    image: "traefik:v2.4.8"
    network_mode: "host"

Upvotes: 0

D.Thomas
D.Thomas

Reputation: 1

i had a similar issue trying to run two different dockers and getting a "Gateway Timeout". My issue was solved after changing the mapping in the second docker for traefik and accessing the site with :84 at the end (http://sitename:84)

  traefik:
    image: traefik:v2.0
    container_name: "${PROJECT_NAME}_traefik"
    command: --api.insecure=true --providers.docker
    ports:
    - '84:80'
    - '8084:8080'

Upvotes: 0

Jonas
Jonas

Reputation: 19

For debugging you could try to configure all container to use the host network to enusre they are realy on the same netwok.

Upvotes: 0

Related Questions