Skip to content

luccasfr/traefik-docker

Repository files navigation

Traefik Docker

Bandeira do Brasil Versão em Português

Requirements

  • Linux operating system
  • Docker and Docker Compose installed and working

What's included?

  • Base Traefik configuration with Docker Compose.
  • Rust application to add hosts to Traefik. (All Rust sources are in ./src)

How to start the Traefik service?

  1. Create a Docker network named web
docker network create web
  1. Replace your email in docker-compose.yml.
--certificatesresolvers.acmeresolver.acme.email=youremail@email.com
  1. Run Traefik
docker compose up -d

How to add a new host using the Rust application?

  1. Download the latest release from GitHub

Go to the Releases page and download the latest version.

Alternatively, you can build from source:

cargo build --release
  1. Run the Rust application

If you built the application from source:

chmod +x ./target/release/add-host
./target/release/add-host

If you downloaded a release:

chmod +x ./add-host*
./add-host*

After following the steps, the application will guide you through the process of adding a new host. The application will add the host to ./config/services/service-name.yml, which is a Docker volume.

  1. Restart Traefik
chmod +x ./restart
./restart

How to add a new host with Docker Compose?

  1. Configure these labels and networks in your service's Docker Compose file:
services:
  your-service:
    image: your-image
    labels:
      - "traefik.enable=true"
      # Replace yourhost.com with your host and your-service with your service name
      - "traefik.http.routers.your-service.rule=Host(`yourhost.com`)"
      - "traefik.http.routers.your-service.tls=true"
      - "traefik.http.routers.your-service.tls.certresolver=acmeresolver"
      - "traefik.http.routers.your-service.entrypoints=websecure"
    # Don't forget to add the service to the web network
    networks:
      - web

# Don't forget to add the service to the web network
networks:
  web:
    external: true

Traefik will automatically detect the last exposed port of the service and add it to the router. If you want to use a different port, you can add the following label:

- "traefik.http.services.your-service.loadbalancer.server.port=8080"
  1. Restart Traefik
chmod +x ./restart
./restart

Authors

Lucas Ferreira

Lucas Ferreira

About

Traefik base docker setup with a Rust app for adding hosts.

Topics

Resources

Stars

Watchers

Forks

Languages