Comment utiliser docker pour s'auto-héberger ? 🐳

De quoi allons nous parler ?

1. Qu'est-ce que l'auto-hébergement ?

2. Pourquoi ?

3. Comment ?

Self-hosted ou "Cloud"

  • WordPress.org
  • Matomo
  • Wallabag
  • WordPress.com
  • Google Analytics
  • Pocket

Pourquoi s'auto-héberger ? 🤔

Pourquoi ne pas s'auto-héberger ? 🙅‍♂️

Tout dans Docker 🐳

Containerize all the things

Pourquoi j'ai choisi Docker

Techno que je connais bien

Est-ce que c'est suffisant pour mes besoins ?

Stable et répandu

Pas (ou peu) de maintenance serveur

Simple à tester en local si besoin

Comment trouver des ressources ? 📚

https://github.com/Kickball/awesome-selfhosted

https://www.reddit.com/r/selfhosted/

https://github.com/veggiemonk/awesome-docker/

https://alternativeto.net

Créer une image soit même et la partager

Comment accéder à tous ces containers ? 🔀

Un serveur par service. Chacun exposé sur le port 80 !

$ docker run -p 80:3000 -d rails

Mettre en place un reverse-proxy

Que fait Traefik ?

Comment ça fonctionne ?

Configuration de base

              
defaultEntryPoints = ["http", "https"]

[entryPoints]
  [entryPoints.http]
    address = ":80"
    [entryPoints.http.redirect]
    entryPoint = "https"
  [entryPoints.https]
    address = ":443"
  [entryPoints.https.tls]

[docker]
watch = true
exposedbydefault = false

[acme]
email = "guillaumebriday@gmail.com"
storage = "acme.json"
entryPoint = "https"

[acme.dnsChallenge]
provider = "gandiv5"
delayBeforeCheck = 0

[[acme.domains]]
  main = "*.guillaumebriday.xyz"
  sans = ["guillaumebriday.xyz"]
              
            

Traefik dans un container

                
- name: Create the traefik container
  docker_container:
    image: traefik
    restart_policy: unless-stopped
    networks:
      - name: web
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - "path/to/traefik.toml:/etc/traefik/traefik.toml"
      - "path/to/acme.json:/acme.json"
      - /var/run/docker.sock:/var/run/docker.sock
    env:
      GANDIV5_API_KEY: "ma-super-cle"
                
              

Configuration par service

Configuration (ou surchage) via les labels de Docker

Configuration par service 🤯

            
- name: Create the nextcloud container
  docker_container:
    name: nextcloud
    image: nextcloud:15
    restart_policy: unless-stopped
    networks:
      - name: web
    labels:
      traefik.frontend.rule: "Host:nextcloud.guillaumebriday.xyz"
      traefik.enable: "true"
      traefik.port: "80"
    volumes:
      - "/var/www/nextcloud/data:/var/www/html"
            
          

Gestion des DNS

Deux lignes suffisent

            
* 10800 IN CNAME guillaumebriday.xyz.
@ 10800 IN A 172.217.18.238
            
          

SSL et Let's Encrypt

  • Demande et renouvellement automatique via un provider 😍
  • ACME http Challange ou DNS Challenge
  • Gestion des certificats Wildcard

Demo ! 👀

Objectif : Remplacer Google Drive.

Repo : https://github.com/guillaumebriday/selfhosted-services/tree/next-cloud

Résultat : https://nextcloud.guillaumebriday.xyz

Review apps simplement avec GitLab 🦊

            
review_app:
  <<: *setup_deploy_env
  stage: review
  script:
    - docker run --rm --name db_${CI_COMMIT_REF_SLUG} -e POSTGRES_DB=${POSTGRES_DB} -e POSTGRES_PASSWORD=secret -d postgres:11

    - docker run --rm -d --name app_${CI_COMMIT_REF_SLUG} \
      --link db_${CI_COMMIT_REF_SLUG} \
      -e DB_HOST=db_${CI_COMMIT_REF_SLUG} \
      -l traefik.frontend.rule=Host:${CI_COMMIT_REF_SLUG}.guillaumebriday.xyz \
      ${IMAGE_TAG}
            
          

Review apps simplement avec GitLab 🦊

Production -> feature/background-red

me

@guillaumebriday - guillaumebriday.fr

https://docker-birthday-6-slides.netlify.com

Merci ! 🙏