Skip to content

OCIO y TECnología

  • Privacy Policy
Offcanvas

  • Register
  • Lost your password ?

OCIO y TECnología

  • Home » 
  • Tecnología » 
  • Docker » 
  • Docker swarm Traefik reverse proxy

Docker swarm Traefik reverse proxy

Emilio González Montaña 2023/08/31 0

In order to serve several Docker services (simple Docker or orchestrated ones via Docker swarm) is good to setup a reverse proxy as Traefik (or Nginx).

This a receipt for deploying Traefik as a Docker swarm stack, including a simple who am I web service to test it.

version: '3.8'

services:

  traefik:
    image: traefik:2.10.4
    command:
      - '--log.level=WARN'
      - '--api.insecure=true'
      - '--providers.docker=true'
      - '--providers.docker.swarmMode=true'
      - '--providers.docker.exposedbydefault=false'
      - '--providers.docker.network=proxy_net'
      - '--entrypoints.http.address=:80'
      - '--entrypoints.http.http.redirections.entryPoint.to=https'
      - '--entrypoints.http.http.redirections.entryPoint.scheme=https'
      - '--entrypoints.https.address=:443'
      - '--entryPoints.https.http.tls=true'
      - '--certificatesresolvers.letsencrypt.acme.httpchallenge=true'
      - '--certificatesresolvers.letsencrypt.acme.httpchallenge.entrypoint=http'
      - '--certificatesresolvers.letsencrypt.acme.email=user@domain.com'
      - '--certificatesresolvers.letsencrypt.acme.storage=/etc/traefik/acme/acme.json'
    volumes:
      - type: bind
        source: /var/run/docker.sock
        target: /var/run/docker.sock
        read_only: true
      - type: bind
        source: /shared/storage/path/traefik
        target: /etc/traefik/acme
    networks:
      - proxy_net
    ports:
      - target: 80
        published: 80
      - target: 443
        published: 443
    deploy:
      mode: global
      placement:
        constraints:
          - node.role==manager
      update_config:
        parallelism: 1
        delay: 10s
      restart_policy:
        condition: on-failure
      labels:
        traefik.enable: 'true'
        traefik.http.routers.https_traefik.rule: 'Host(`traefik.domain.com`)'
        traefik.http.routers.https_traefik.entrypoints: 'https'
        traefik.http.routers.https_traefik.tls.certresolver: 'letsencrypt'
        traefik.http.services.traefik.loadbalancer.server.port: '8080'

  whoami:
    image: containous/whoami:v1.5.0
    networks:
      - proxy_net
    deploy:
      labels:
        traefik.enable: 'true'
        traefik.http.routers.https_whoami.rule: 'Host(`whoami.domain.com`)'
        traefik.http.routers.https_whoami.entrypoints: 'https'
        traefik.http.routers.https_whoami.tls.certresolver: 'letsencrypt'
        traefik.http.services.whoami.loadbalancer.server.port: '80'

networks:
  proxy_net:
    external: true

Some interesting features of this configuration:

  • It declares an external overlay network, it should be pre created before adding the stack, being external allows to redeploy the stack without errors because this network is used by other stacks.
  • It includes auto provision of Let’s Encrypt SSL certificates, you need Internet connection at those Docker servers, also replace the admin email & domain names (for base domain at Traefik configuration, and auto provisioned web URLs), Traefik should be allowed to use HTTP (80/tcp) and HTTPS (443/tcp) ports.
  • No extra tedious configuration files are required, all is defined at the YAML file.
  • Traefik is configured to listen to Docker socket in order to auto discover any new Docker container requesting new sub URI of the defined base domain configured at Traefik service, this is my preferred behaviour for a reverse proxy, new services (as “who am I”) will add a few deployment labels to ask Traefik to do the job (in deed Traefik is the one reading those labels). Take care Traefik service should be placed in a manager node in order to do its job, placement constraint was added on deploy section.

Comparte esto:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
Tags : Tags docker   docker-compose.yml   docker-swarm   traefik
Share
facebookShare on FacebooktwitterShare on TwitterpinterestShare on Pinterest
linkedinShare on LinkedinvkShare on VkredditShare on ReddittumblrShare on TumblrviadeoShare on ViadeobufferShare on BufferpocketShare on PocketwhatsappShare on WhatsappviberShare on ViberemailShare on EmailskypeShare on SkypediggShare on DiggmyspaceShare on MyspacebloggerShare on Blogger YahooMailShare on Yahoo mailtelegramShare on TelegramMessengerShare on Facebook Messenger gmailShare on GmailamazonShare on AmazonSMSShare on SMS
Post navigation
Previous post

Upgrading to Proxmox 8

Next post

Cannot open Proxmox VM console

Emilio González Montaña

Related Posts

Categories Linux  Networking  Tecnología Docker swarm Traefik reverse proxy

Detachable screens to avoid SSH disconnections

Categories Linux  Networking  Tecnología Docker swarm Traefik reverse proxy

Expose WSL2 port to the network

Categories Data bases  Docker  Tecnología Docker swarm Traefik reverse proxy

Recover corrupted Postgres DB WAL

Leave a Comment Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • Detachable screens to avoid SSH disconnections
  • Expose WSL2 port to the network
  • Rosaleda (parque El Retiro, Madrid)
  • Back to the painting table
  • Recover corrupted Postgres DB WAL

Categories

  • Aficiones
  • AI
  • Bricolage
  • Data bases
  • Docker
  • Escenografía
  • Eventos
  • Fotografía
  • Hardware
  • Linux
  • Networking
  • Partidas
  • Proxmox
  • Sin categoría
  • Tecnología
  • Utils
  • Viajes
  • Virtualization
  • Warhammer
  • YAML

Tags

anthill (1) apt (5) cellular-automatons (1) ceph (2) context (1) conways-life (1) cortador (1) debian (3) docker (9) docker-compose.yml (4) docker-swarm (5) DRY (1) El Imperio (2) Enanos (2) escenografía (3) fotos (3) GlusterFS (1) Guerreros del Caos (2) informática (1) Linux (8) M.2 (1) Mac (1) Madrid (2) maqueta (2) MariaDB (2) miniaturas (4) MySQL (2) NFS (2) NVMe (1) partida (2) poliestireno (1) portainer (1) proxmox (2) rocas (1) Sony A65 (2) SSH (5) ssh-key (1) Ubuntu (8) update (2) volume (1) Warhammer (11) Windows (3) WSL (2) WSL2 (2) YAML (1)

Archives

  • June 2024
  • May 2024
  • April 2024
  • February 2024
  • January 2024
  • September 2023
  • August 2023
  • June 2023
  • December 2021
  • April 2021
  • May 2020
  • April 2020
  • March 2020
  • November 2019
  • July 2018
  • February 2017
  • June 2015
  • April 2014
  • April 2011
  • January 2011
  • July 2010
  • June 2010
  • March 2010
  • November 2009
  • June 2009
  • December 2008
  • November 2008
  • October 2008
  • June 2008
  • May 2008
  • October 2007

Meta

  • Register
  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
Copyright © 2025 OCIO y TECnología - Powered by Nevothemes.
Offcanvas