plankanban / planka

The realtime kanban board for workgroups built with React and Redux.
https://planka.app
GNU Affero General Public License v3.0
7.81k stars 727 forks source link

Issue with Planka and Traefik. #157

Open Zeropeace opened 3 years ago

Zeropeace commented 3 years ago

Hi all,

I want to run Planka in docker container with Traefik as a reverse Proxy . But i have encountered a problem. If i route Planka thru Traefik i can only get to the Log In page and then after i log in it keeps loading for ever. This does not occur when i acces it with the IP:PORT combo. I have added my docker-compose and traefik config. I also found a cryptic log from Traefik wich might be useful.

docker-compose:

version: '3'

services:
  planka:
    image: meltyshev/planka:latest
    command: >
      bash -c
        "for i in `seq 1 30`; do
          ./start.sh &&
          s=$$? && break || s=$$?;
          echo \"Tried $$i times. Waiting 5 seconds...\";
          sleep 5;
        done; (exit $$s)"
    restart: unless-stopped
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - user-avatars:/app/public/user-avatars
      - project-background-images:/app/public/project-background-images
      - attachments:/app/public/attachments
    networks:
      - proxy
    ports:
      - 3000:1337
    environment:
      - BASE_URL=http://planka.mydomain.com
      - DATABASE_URL=postgresql://postgres@postgres/planka
      - SECRET_KEY=added a realy secret key here
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.planka.entrypoints=http"
      - "traefik.http.routers.planka.rule=Host(`planka.mydomain.com`)"
      - "traefik.http.middlewares.planka-https-redirect.redirectscheme.scheme=https"
      - "traefik.http.routers.planka.middlewares=planka-https-redirect"
      - "traefik.http.routers.planka-secure.entrypoints=https"
      - "traefik.http.routers.planka-secure.rule=Host(`planka.mydomain.com`)"
      - "traefik.http.routers.planka-secure.tls=true"
      - "traefik.http.routers.planka-secure.service=planka"
      - "traefik.http.services.planka.loadbalancer.server.port=1337"
      - "traefik.docker.network=proxy"
    depends_on:
      - postgres

  postgres:
    image: postgres:alpine
    restart: unless-stopped
    volumes:
      - db-data:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=planka
      - POSTGRES_HOST_AUTH_METHOD=trust

volumes:
  user-avatars:
  project-background-images:
  attachments:
  db-data:

networks:
  proxy:
    external: true
Traefik config: 

http:
  routers:
    pihole:
      entryPoints:
        - "https"
        - "http"
      rule: "Host(`pihole.my.domain`)"
      middlewares:
        - default-headers
        - addprefix-pihole
      tls: {}
      service: pihole
    heimdall:
      entryPoints:
        - "https"
        - "http"
      rule: "Host(`heimdall.my.domain`)"
      middlewares:
        - default-headers
      tls: {}
      service: heimdall
    wq:
      entryPoints:
        - "https"
        - "http"
      rule: "Host(`wq.my.domain`)"
      middlewares:
        - default-headers
      tls: {}
      service: wq
    planka:
      entryPoints:
        - "https"
        - "http"
      rule: "Host(`planka.my.domain`)"
      middlewares:
        - default-headers
      tls: {}
      service: planka

  services:
    pihole:
      loadBalancer:
        servers:
          - url: "http://192.168.178.65:80"
        passHostHeader: true
    heimdall:
      loadBalancer:
        servers:
          - url: "http://192.168.178.52:8080"
        passHostHeader: true
    wq:
      loadBalancer:
        servers:
          - url: "http://192.168.178.43:3000"
        passHostHeader: true
    planka:
      loadBalancer:
        servers:
          - url: "http://192.168.178.85:3000"
        passHostHeader: true

  middlewares:
    addprefix-pihole:
      addPrefix:
        prefix: "/admin"
    https-redirect:
      redirectScheme:
        scheme: https

    default-headers:
      headers:
        frameDeny: true
        sslRedirect: true
        browserXssFilter: true
        contentTypeNosniff: true
        forceSTSHeader: true
        stsIncludeSubdomains: true
        stsPreload: true
        stsSeconds: 15552000
        customFrameOptionsValue: SAMEORIGIN
        customRequestHeaders:
          X-Forwarded-Proto: https

    default-whitelist:
      ipWhiteList:
        sourceRange:
        - "10.0.0.0/24"
        - "192.168.0.0/16"
        - "172.0.0.0/8"

    secured:
      chain:
        middlewares:
        - default-whitelist
        - default-headers

Screenshot 2021-08-30 230220

nickbe commented 3 years ago

I don't think anyone has ever tested Traefik. But anyway Traefik is supposed to detect the needed configuration as far as I know. If it doesn't (and I quote from its community) you're more than often fucked. There's simply not the time to experiment with non-standard proxy software. Sorry

shamoon commented 3 years ago

Yea as he said, in so many words, traefik is awesome when it just works but a little mysterious when it doesnt. I have it working in my setup FWIW (+ authelia), biggest difference is I use traefik docker labels which does the auto configuration magic, see below in case it helps you...

  planka:
    image: meltyshev/planka:latest
    container_name: planka
    command: >
      bash -c
        "for i in `seq 1 30`; do
          ./start.sh &&
          s=$$? && break || s=$$?;
          echo \"Tried $$i times. Waiting 5 seconds...\";
          sleep 5;
        done; (exit $$s)"
    restart: unless-stopped
    volumes:
      - /path/to/planka/avatars:/app/public/user-avatars
      - /path/to/planka/background-images:/app/public/project-background-images
      - /path/to/planka/attachments:/app/public/attachments
    ports:
      - 1337:1337
    environment:
      - BASE_URL=https://tasks.domain.com
      - DATABASE_URL=postgresql://postgres@planka-db/planka
      - SECRET_KEY=***
    depends_on:
      - planka-db
    networks:
      - macvlan_network
      - traefik_proxy
      - default
    labels:
      - traefik.http.routers.planka.rule=Host(`tasks.domain.com`)
      - traefik.http.routers.planka.tls.certresolver=le
      - traefik.http.routers.planka.entrypoints=websecure
      - traefik.http.routers.planka.middlewares=chain-authelia
      - traefik.http.services.planka.loadbalancer.server.port=1337
      - traefik.docker.network=traefik_proxy
johnchristopher commented 3 years ago

I want to run Planka in docker container with Traefik as a reverse Proxy . But i have encountered a problem. If i route Planka thru Traefik i can only get to the Log In page and then after i log in it keeps loading for ever. This does not occur when i acces it with the IP:PORT combo. I have added my docker-compose and traefik config. I also found a cryptic log from Traefik wich might be useful.

Here's an alternative: run Traefik in a container. It's easier to manage your services and network, no IP or port to configure on your host.

If you want I can dust off a pi and give you a running config for both Traefik and Planka.

The configuration you posted is a bit weird to me because I read some pihole and plank.my.domain in the same Traefik config but you can't run it on a local network in front of a pihole and on public server. What's your network setup ?

What it means is that your planka container's IP may change everytime you recreate the container:

     planka:
      loadBalancer:
        servers:
          - url: "http://192.168.178.85:3000"

Traefik can only read a container's labels when linked to the docker socket.

loranger commented 3 years ago

I use traefik as a container, auto-discovering docker containers. I also had this forever loading bug until I changed the BASE_URLenvironment variable, matching the https (instead of http) traefik rule I defined in order to make planka reachable from outside.

My conf is a little bit different, but in case it may help, here it is

.env ```shell APP_PROJECT=planka APP_DOMAIN=kanban.my.domain POSTGRES_HOST=${APP_PROJECT}-postgres POSTGRES_USER=postgres POSTGRES_PASSWORD=postgres POSTGRES_DB=planka # POSTGRES_HOST_AUTH_METHOD=trust BASE_URL=https://${APP_DOMAIN} DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}/${POSTGRES_DB} SECRET_KEY=my-secret-key ```
docker-compose.yml ```yaml version: '3' services: planka: image: meltyshev/planka:latest command: > bash -c "for i in `seq 1 30`; do ./start.sh && s=$$? && break || s=$$?; echo \"Tried $$i times. Waiting 5 seconds...\"; sleep 5; done; (exit $$s)" restart: unless-stopped volumes: - user-avatars:/app/public/user-avatars - project-background-images:/app/public/project-background-images - attachments:/app/public/attachments # ports: # - 3000:1337 env_file: - .env labels: - "traefik.http.routers.${APP_PROJECT}.entrypoints=http" - "traefik.http.routers.${APP_PROJECT}.rule=Host(`${APP_DOMAIN}`)" - "traefik.http.routers.${APP_PROJECT}.middlewares=redirect-without-www@file,redirect-to-https@file" - "traefik.http.routers.${APP_PROJECT}-secure.entrypoints=https" - "traefik.http.routers.${APP_PROJECT}-secure.rule=Host(`${APP_DOMAIN}`)" - "traefik.http.routers.${APP_PROJECT}-secure.tls=true" - "traefik.http.routers.${APP_PROJECT}-secure.tls.certresolver=letsencrypt" - "traefik.http.routers.${APP_PROJECT}-secure.middlewares=redirect-without-www@file" - "com.centurylinklabs.watchtower.enable=true" depends_on: - postgres postgres: image: postgres:alpine restart: unless-stopped container_name: ${APP_PROJECT}-postgres volumes: - db-data:/var/lib/postgresql/data env_file: - .env labels: - "traefik.enable=false" volumes: user-avatars: project-background-images: attachments: db-data: networks: default: name: traefik-shared-network ```
Underknowledge commented 2 years ago

Have been fighting this for a couple of hours now. apparently the planka container has issues with multiple networks

planka_1    | Error: connect EHOSTUNREACH 192.168.0.2:5432
planka_1    |     at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1138:16) {
planka_1    |   errno: -113,
planka_1    |   code: 'EHOSTUNREACH',
planka_1    |   syscall: 'connect',
planka_1    |   address: '192.168.0.2',
planka_1    |   port: 5432
planka_1    | }

at some point I tryed to bindmount the Unix socket into the container, but the DATABASE_URL didn't took this and always failed back to localhost, bummer..

not working:

version: '3'

# as per https://github.com/plankanban/planka/blob/master/docker-compose.yml
services:
  planka:
    image: meltyshev/planka:latest
    command: >
      bash -c
        "for i in `seq 1 30`; do
          ./start.sh &&
          s=$$? && break || s=$$?;
          echo \"Tried $$i times. Waiting 5 seconds...\";
          sleep 5;
        done; (exit $$s)"
    restart: unless-stopped
    volumes:
      - ${PROJECT_FOLDER}/user-avatars:/app/public/user-avatars
      - ${PROJECT_FOLDER}/project-background-images:/app/public/project-background-images
      - ${PROJECT_FOLDER}/attachments:/app/public/attachments
      - ${PROJECT_FOLDER}/pg-run:/var/run/postgresql 
    env_file:
      - ${PROJECT_FOLDER}/.env
#    ports:
#      - 3000:1337
    networks:
      - traefik
      - internal_planka
    environment:
      - BASE_URL=${BASE_URL}
      - TRUST_PROXY=0
      - DATABASE_URL=postgresql://postgres@postgres_planka/planka
      - SECRET_KEY=${SECRET_KEY}
    depends_on:
      - postgres_planka
    labels:
      - traefik.http.routers.planka.rule=Host(`kanban.${DOMAINNAME}`)
      - traefik.http.services.planka.loadbalancer.server.port=1337
      - traefik.docker.network=traefik

  postgres_planka: 
    image: postgres:alpine
    container_name: postgres_planka
    restart: unless-stopped
    volumes:
      - ${PROJECT_FOLDER}/db-data:/var/lib/postgresql/data
    networks:
      - internal_planka
#    expose: # no diffrence
#      - 5432
    environment:
      - POSTGRES_DB=planka
      - POSTGRES_HOST_AUTH_METHOD=trust

networks:
  internal_planka:
    name: internal_planka
    internal: true
  traefik:
    name: traefik
    external: true

working:

version: '3'

# as per https://github.com/plankanban/planka/blob/master/docker-compose.yml
services:
  planka:
    image: meltyshev/planka:latest
    command: >
      bash -c
        "for i in `seq 1 30`; do
          ./start.sh &&
          s=$$? && break || s=$$?;
          echo \"Tried $$i times. Waiting 5 seconds...\";
          sleep 5;
        done; (exit $$s)"
    restart: unless-stopped
    volumes:
      - ${PROJECT_FOLDER}/user-avatars:/app/public/user-avatars
      - ${PROJECT_FOLDER}/project-background-images:/app/public/project-background-images
      - ${PROJECT_FOLDER}/attachments:/app/public/attachments
      - ${PROJECT_FOLDER}/pg-run:/var/run/postgresql 
    env_file:
      - ${PROJECT_FOLDER}/.env
#    ports:
#      - 3000:1337
    networks:
      - traefik
    environment:
      - BASE_URL=${BASE_URL}
      - TRUST_PROXY=0
      - DATABASE_URL=postgresql://postgres@postgres_planka/planka
      - SECRET_KEY=${SECRET_KEY}
    depends_on:
      - postgres_planka
    labels:
      - traefik.http.routers.planka.rule=Host(`kanban.${DOMAINNAME}`)
      - traefik.http.services.planka.loadbalancer.server.port=1337
      - traefik.docker.network=traefik

  postgres_planka: 
    image: postgres:alpine
    container_name: postgres_planka
    restart: unless-stopped
    volumes:
      - ${PROJECT_FOLDER}/db-data:/var/lib/postgresql/data
    networks:
      - traefik
#    expose: # no diffrence
#      - 5432
    environment:
      - POSTGRES_DB=planka
      - POSTGRES_HOST_AUTH_METHOD=trust

networks:
  traefik:
    name: traefik
    external: true

Why this is the case, I really have no idea. The only container that displayed this absurd behaviour was keycloak.

on a personal note, @loranger cool trick with the collapsible code snippets, when I try it the shared code gets all wonky, care to share how you did this?

loranger commented 2 years ago

5432 is the PostgreSQL default port. It could be postgres which is not started, or incorrect credentials or connections not allowed from 192.168.0.2. The latter should be the real issue because planka seems working fine with one network only. I'm no specialist, but you should take a look at the postgresql conf (maybe pg_hba.conf file) use by default inside postgres:alpine image

Regarding the collapsible markup, you should take a look at the cheatsheet and then figure out your code was certainly messy because of the missing blank lines. Now you can use it as soon as you have too much lines to share. At least that's what I do ;)

Underknowledge commented 2 years ago

I installed telnet inside of the app container and tried to reach the the PG database. I think I was getting a Connection refused but cant be certain anymore. The resolved IP was right, but even a nmap scan didn't showed a open PG port. But on the other side, the name resolution works. I thought the POSTGRES_HOST_AUTH_METHOD var would work around this. Had like 15 edidts, but the yaml code-block just thew up on my tryes .

test title, ignore me version: '3' # as per https://github.com/plankanban/planka/blob/master/docker-compose.yml services: planka: image: meltyshev/planka:latest command: > bash -c "for i in `seq 1 30`; do ./start.sh && s=$$? && break || s=$$?; echo \"Tried $$i times. Waiting 5 seconds...\"; sleep 5; done; (exit $$s)" restart: unless-stopped volumes: - ${PROJECT_FOLDER}/user-avatars:/app/public/user-avatars - ${PROJECT_FOLDER}/project-background-images:/app/public/project-background-images - ${PROJECT_FOLDER}/attachments:/app/public/attachments - ${PROJECT_FOLDER}/pg-run:/var/run/postgresql env_file: - ${PROJECT_FOLDER}/.env # ports: # - 3000:1337 networks: - traefik environment: - BASE_URL=${BASE_URL} - TRUST_PROXY=0 - DATABASE_URL=postgresql://postgres@postgres_planka/planka - SECRET_KEY=${SECRET_KEY} depends_on: - postgres_planka labels: - traefik.http.routers.planka.rule=Host(`kanban.${DOMAINNAME}`) - traefik.http.services.planka.loadbalancer.server.port=1337 - traefik.docker.network=traefik postgres_planka: image: postgres:alpine container_name: postgres_planka restart: unless-stopped volumes: - ${PROJECT_FOLDER}/db-data:/var/lib/postgresql/data networks: - traefik # expose: # no diffrence # - 5432 environment: - POSTGRES_DB=planka - POSTGRES_HOST_AUTH_METHOD=trust networks: traefik: name: traefik external: true

edit: yea, still looks like ****

edit: Didnt closed the shell window

/app # bash
bash-5.0# telnet postgres_planka
telnet: can't connect to remote host (172.28.0.2): Host is unreachable
bash-5.0# telnet postgres_planka ^C
bash-5.0# ^C
bash-5.0# ping postgres_planka
PING postgres_planka (172.28.0.2): 56 data bytes
64 bytes from 172.28.0.2: seq=0 ttl=64 time=0.112 ms
64 bytes from 172.28.0.2: seq=1 ttl=64 time=0.221 ms
^C
--- postgres_planka ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 0.112/0.166/0.221 ms
bash-5.0# telnet postgres_planka
telnet: can't connect to remote host (172.28.0.2): Host is unreachable
bash-5.0# telnet postgres_planka 5432
telnet: can't connect to remote host (172.28.0.2): Host is unreachable
Host is up (0.00011s latency).
rDNS record for 172.28.0.2: postgres_planka.kanban-planka_internal
All 1000 scanned ports on postgres_planka (172.28.0.2) are filtered
MAC Address: 02:42:AC:1C:00:02 (Unknown)

Nmap done: 1 IP address (1 host up) scanned in 5.54 seconds
itobetter commented 12 months ago

hi guys i have the same error, my solution it was set the same BASE_URL as traefik.http.routers.server.rule traefik parameter, in others worlds