Traefik + springboot + docker compose

I have Traefik + springboot docker compose file. I am not sure what am I missing. I have tried few approached and cannot get it to work and I need expert advise on the issue I am facing.

Below is my docker-compose file. Springboot application exposes 8080.

version: '3.8'

services:
  traefik:
    image: "traefik:v3.0"
    container_name: "traefik"
    command:
      #- "--log.level=DEBUG"
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entryPoints.web.address=:80"
      - "--entryPoints.websecure.address=:443"
      - "--certificatesresolvers.myresolver.acme.httpchallenge=true"
      - "--certificatesresolvers.myresolver.acme.httpchallenge.entrypoint=web"
      #- "--certificatesresolvers.myresolver.acme.caserver=https://acme-staging-v02.api.letsencrypt.org/directory"
      - "--certificatesresolvers.myresolver.acme.email=my_email@gmail.com"
      - "--certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json"
    ports:
      - "80:80"
      - "443:443"
      - "8080:8080"
    volumes:
      - "./letsencrypt:/letsencrypt"
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
    networks:
      - web

  springboot-app:
    image: springboot-app/app:2.1.5
    container_name: springboot-app
    environment:
      - SPRING_DATASOURCE_URL=jdbc:postgresql://postgres:5432/app
      - SPRING_DATASOURCE_USERNAME=app
      - SPRING_DATASOURCE_PASSWORD=app
      - SPRING_JPA_HIBERNATE_DDL_AUTO=update
    ports:
      - 8080
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.springboot.rule=Host(`mydomain.com`)"
      - "traefik.http.routers.springboot.entrypoints=web"
      - "traefik.http.routers.springboot.tls=true"
      - "traefik.http.routers.springboot.tls.certresolver=myresolver"
      - "traefik.http.services.springboot.loadbalancer.server.port=8080"
    depends_on:
      - postgres
    networks:
      - web

  postgres:
    image: postgres:14-alpine
    container_name: postgres
    ports:
      - "5432:5432"
    restart: always
  environment:
      - POSTGRES_USER=USER
      - POSTGRES_PASSWORD=PASSWORD
    volumes:
      - ./data:/var/lib/postgresql/data
    networks:
      - web

volumes:
  postgres_data:
  traefik_certificates:

networks:
  web:
    external: false

FYI... changing web to websecure returns this error in browser
Bad Request
This combination of host and port requires TLS.

Your config seems strange, you enable TLS on http (port 80) entrypoint. Compare to simple Traefik example.

I enabled 8080 and expose it as per the simple example and I am still getting error. Any suggestion on this error?


"Use of closed network connection" usually only happens during shutdown.

It seems the error is gone now. Yet the network traffic is not routing to my springboot service via load balancer. This setup is running on AWS EC2. Without traefik, I am able to call springboot api using my domain name and it works as expected. I did created SSL keys locally, I am not sure if that is causing the issue but no logs traefik to --> springboot

Try and remove the line:

That did not help. Looks like mandatory flag

I meant to remove it on the router. Not entrypoint itself. Sorry for being unclear.

I apologize for newbie errors and grateful for helping me. There are no issues starting up the application. However, I am unable to access the API using domain.com on browser.
I enabled logs on traefik and all logs looks good. I couldn't see any issues with setup and connection with springboot service

The error is
Bad Request
This combination of host and port requires TLS.

This is very unspecific. The error message indicates you try to use http with port 443 or similar.

Enable Traefik access log in JSON, check for OriginStatus and DownstreamStatus to identify if error comes from target service or Traefik.

Share your current full config. Compare to simple Traefik example.