DEV Community

M
M

Posted on

1

docker + traefik vhost to container proxy ( single machine )

lets create tnet first with:

docker network create tnet
Enter fullscreen mode Exit fullscreen mode

then create traefik folder and put following contents to docker-compose.yml

version: "3.9"
services:
  traefik:
    image: traefik
    restart: always
    command:
      - "--log.level=DEBUG"
      - '--providers.docker.exposedByDefault=false'
      - "--entrypoints.web.address=:80"
      - "--entrypoints.websecure.address=:443"
      - "--serverstransport.insecureskipverify=true"
      - "--certificatesresolvers.le.acme.storage=/acme.json"
      - "--certificatesresolvers.le.acme.tlschallenge=true"
      - "--certificatesresolvers.le.acme.httpchallenge.entrypoint=web"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    labels:
      - traefik.enable=true
    ports:
      - "80:80"
      - "443:443"
    networks:
      - lanuske


networks:
  tnet:
    name: tnet
    external: true

Enter fullscreen mode Exit fullscreen mode

enter traefik directory and run docker-compose up -d

and config for each "microservice"

version: "3.9" 
  # other containres
  # db:
  # image: mariadb:latest

  # this with traefik tags, will be exposed to the internet with a subdomain name
  nginx:
    image: nginx
    restart: always
    labels:
      - traefik.enable=true
      - traefik.http.routers.your-uniq-router-http.entrypoints=web
      - traefik.http.routers.your-uniq-router-http.rule=Host(`container-name.domain.tld`)
      - traefik.http.routers.your-uniq-router-https.entrypoints=websecure
      - traefik.http.routers.your-uniq-router-https.rule=Host(`container-name.domain.tld`)
      - traefik.http.routers.your-uniq-router-https.tls.certresolver=le
      - traefik.http.routers.your-uniq-router-https.tls=true
      - traefik.http.services.your-uniq-router-https.loadbalancer.server.port=80 #nginx port
    networks:
      - tnet

networks:
  tnet:
    name: tnet
    external: true
Enter fullscreen mode Exit fullscreen mode

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay