mother-of-all-self-hosting / mash-playbook

🐋 Ansible playbook which helps you host various FOSS services as Docker containers on your own server
GNU Affero General Public License v3.0
484 stars 64 forks source link

How do you run other containers with the traefik that this book sets up? #183

Open BettyNutz opened 7 months ago

BettyNutz commented 7 months ago

I've set up a server using this playbook. Its running a few services (eg synthing) that ive chosen by adding to vars file and they all working behind traefik. Great. but im struggling to run other docker containers using the traefik thats installed.

I understand the doc to config the dns for eg syncthing - id go to https://mash.example.com/syncthing and it get the synthign UI. Great

But how do i get my website to be on the main domain https://example.com/ and have it running behind traefik?

Not sure how to get it working - new to Ansible with a few playbooks under my belt but this one is way more complicated

this is what id use to get the PrestaShop working usually:

services:
  mariadb:
    container_name: mariadb
    image: docker.io/bitnami/mariadb:latest
    environment:
      - ALLOW_EMPTY_PASSWORD=no
      - MARIADB_ROOT_PASSWORD=AzfrZEby2PKyyH59P
      - MARIADB_DATABASE=prestashop_2024
      - MARIADB_USER=example2024
      - MARIADB_PASSWORD=gyeGjEZ92obHWg#Y#d7
    volumes:
      - /home/user/bitnami/mariadb:/bitnami/mariadb
    networks:
      - prestashop-net

  prestashop:
    container_name: prestashop
    image: docker.io/bitnami/prestashop:latest
    environment:
      - PRESTASHOP_HOST=example.com
      - PRESTASHOP_TIMEZONE=Asia/Singapore
      - PRESTASHOP_DATABASE_HOST=mariadb
      - PRESTASHOP_DATABASE_PORT_NUMBER=3306
      - PRESTASHOP_DATABASE_USER=example2024
      - PRESTASHOP_DATABASE_NAME=prestashop_2024
      - PRESTASHOP_DATABASE_PASSWORD=gyeGjEZ92obHWg#Y#d7
      - PRESTASHOP_FIRST_NAME=user
      - PRESTASHOP_LAST_NAME=Nuser
      - PS_DEV_MODE=0
      - PS_DEMO_MODE=0
      - PS_FOLDER_ADMIN=admin076vwy4oc
      - PRESTASHOP_PASSWORD=customer_support@example.com
      - PRESTASHOP_EMAIL=customer_support@example.com
      - PHP_UPLOAD_MAX_FILESIZE=0M
      - PHP_MEMORY_LIMIT=512M
      - ALLOW_EMPTY_PASSWORD=no
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.prestashop.rule=Host(`example.com`)"
      - "traefik.http.routers.prestashop.entrypoints=traefik"
      - "traefik.http.services.prestashop.loadbalancer.server.port=80"
    volumes:
      - /home/user/prestashop:/bitnami/prestashop
    depends_on:
      - mariadb
    networks:
      - prestashop-net
      - traefik

  phpmyadmin:
    container_name: myphpadmin
    image: phpmyadmin/phpmyadmin
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.phpmyadmin.rule=Host(`phpmyadmin.example.com`)"
      - "traefik.http.routers.phpmyadmin.entrypoints=traefik"
      - "traefik.http.services.phpmyadmin.loadbalancer.server.port=80"
    networks:
      - prestashop-net
      - traefik

networks:
  prestashop-net:
    external: true
  traefik:
    external: true

volumes:
  mariadb_data:
    driver: local
  prestashop_data:
    driver: local
moan0s commented 7 months ago

Here is a quick example of how I do it:

➜  /static_sites cat docker-compose.yml 
version: "3.3"

services:
  example.org:
    image: docker.io/joseluisq/static-web-server:2
    container_name: "example.org"
    environment:
      # Note: those envs are customizable but also optional
      - SERVER_PORT=8080
      - SERVER_ROOT=/public
      - SERVER_LOG_LEVEL=info
    volumes:
      - /static_sites/static-calendar-cje/example.org:/public
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=traefik"
      - "traefik.http.routers.static-calendar-cje.rule=Host(`example.org`)"
      - "traefik.http.routers.static-calendar-cje.service=static-calendar-cje-service"
      - "traefik.http.routers.static-calendar-cje.entrypoints=web-secure"
      - "traefik.http.routers.static-calendar-cje.tls=true"
      - "traefik.http.routers.static-calendar-cje.tls.certResolver=default"
      - "traefik.http.services.static-calendar-cje-service.loadbalancer.server.port=8080"
    networks:
      - traefik

This is an example for a static site but you could do this for any container.

If you are interested in static sites you might want to check out my ansible playbook to set them up easily: https://git.hyteck.de/moanos/ansible-playbook-static-site-host.git

metaminux commented 3 weeks ago

@BettyNutz Did this answer your question ?

I had to struggle also to get my other services running (old owncloud, gitlab, etherpad, odoo) and find the right set of labels to get it right.

Maybe a PR for adding a section in documentation would be nice... @spantaleev @moan0s @aine-etke ?