Advertisement
moltra

Docker Compose

Jun 2nd, 2023 (edited)
1,799
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 9.64 KB | None | 0 0
  1. version: "3.9"
  2. ########################### NETWORKS
  3. # You may customize the network subnet (192.168.90.0/24) below as you please.
  4. # Docker Compose version 3.5 or higher required to define networks this way.
  5.  
  6. networks:
  7.   t2_proxy:
  8.     name: t2_proxy
  9.     driver: bridge
  10.     ipam:
  11.       config:
  12.         - subnet: 192.168.90.0/24
  13.   default:
  14.     driver: bridge
  15.   # socket_proxy:
  16.   #   name: socket_proxy
  17.   #   driver: bridge
  18.   #   ipam:
  19.   #     config:
  20.   #       - subnet: 192.168.91.0/24
  21.  
  22. ########################### EXTENSION FIELDS
  23. # Helps eliminate repetition of sections
  24. # More Info on how to use this: https://github.com/htpcBeginner/docker-traefik/pull/228
  25.  
  26. # Common environment values
  27. x-environment: &default-tz-puid-pgid
  28.   TZ: $TZ
  29.   PUID: $PUID
  30.   PGID: $PGID
  31.  
  32. # Keys common to some of the core services that we always to automatically restart on failure
  33. x-common-keys-core: &common-keys-core
  34.   networks:
  35.    - t2_proxy
  36.   security_opt:
  37.    - no-new-privileges:true
  38.   restart: always
  39.  
  40. # Keys common to some of the dependent services/apps
  41. x-common-keys-apps: &common-keys-apps
  42.   networks:
  43.    - t2_proxy
  44.   security_opt:
  45.    - no-new-privileges:true
  46.   restart: unless-stopped
  47.  
  48. # Keys common to some of the services in media-services.txt
  49. x-common-keys-media: &common-keys-media
  50.   networks:
  51.    - t2_proxy
  52.   security_opt:
  53.    - no-new-privileges:true
  54.   restart: "no"
  55.  
  56. ########################### SERVICES
  57. services:
  58. # Traefik 2 - Reverse Proxy
  59.   traefik:
  60.     <<: *common-keys-core # See EXTENSION FIELDS at the top
  61.     container_name: traefik
  62.     image: traefik:2.7
  63.     command: # CLI arguments
  64.       - --global.checkNewVersion=true
  65.       - --global.sendAnonymousUsage=true
  66.       - --entryPoints.http.address=:80
  67.       - --entryPoints.https.address=:443
  68.       # Allow these IPs to set the X-Forwarded-* headers - Cloudflare IPs: https://www.cloudflare.com/ips/
  69.       - --entrypoints.https.forwardedHeaders.trustedIPs=$CLOUDFLARE_IPS,$LOCAL_IPS
  70.       - --entryPoints.traefik.address=:8080
  71.       - --api=true
  72.       # - --api.insecure=true
  73.       - --api.dashboard=true
  74.       # - --serversTransport.insecureSkipVerify=true
  75.       - --log=true
  76.       - --log.filePath=/logs/traefik.log
  77.       - --log.level=DEBUG # (Default: error) DEBUG, INFO, WARN, ERROR, FATAL, PANIC
  78.       - --accessLog=true
  79.       - --accessLog.filePath=/logs/access.log
  80.       - --accessLog.bufferingSize=100 # Configuring a buffer of 100 lines
  81.       - --accessLog.filters.statusCodes=204-299,400-499,500-599
  82.       - --providers.docker=true
  83.       - --providers.docker.endpoint=unix:///var/run/docker.sock # Use Docker Socket Proxy instead for improved security
  84.       # - --providers.docker.endpoint=tcp://socket-proxy:2375 # Use this instead of the previous line if you have socket proxy.
  85.       - --providers.docker.exposedByDefault=false
  86.       - --entrypoints.https.http.tls.options=tls-opts@file
  87.       # Add dns-cloudflare as default certresolver for all services. Also enables TLS and no need to specify on individual services
  88.       - --entrypoints.https.http.tls.certresolver=dns-cloudflare
  89.       - --entrypoints.https.http.tls.domains[0].main=$DOMAINNAME_CLOUD_SERVER
  90.       - --entrypoints.https.http.tls.domains[0].sans=*.$DOMAINNAME_CLOUD_SERVER
  91.       # - --entrypoints.https.http.tls.domains[1].main=$DOMAINNAME2 # Pulls main cert for second domain
  92.       # - --entrypoints.https.http.tls.domains[1].sans=*.$DOMAINNAME2 # Pulls wildcard cert for second domain
  93.       - --providers.docker.network=t2_proxy
  94.       - --providers.docker.swarmMode=false
  95.       - --providers.file.directory=/rules # Load dynamic configuration from one or more .toml or .yml files in a directory
  96.       # - --providers.file.filename=/path/to/file # Load dynamic configuration from a file
  97.       - --providers.file.watch=true # Only works on top level files in the rules folder
  98.       #- --certificatesResolvers.dns-cloudflare.acme.caServer=https://acme-staging-v02.api.letsencrypt.org/directory # LetsEncrypt Staging Server - uncomment when testing
  99.       - --certificatesResolvers.dns-cloudflare.acme.email=$CLOUDFLARE_EMAIL
  100.       - --certificatesResolvers.dns-cloudflare.acme.storage=/acme.json
  101.       - --certificatesResolvers.dns-cloudflare.acme.dnsChallenge.provider=cloudflare
  102.       - --certificatesResolvers.dns-cloudflare.acme.dnsChallenge.resolvers=1.1.1.1:53,1.0.0.1:53
  103.       - --certificatesResolvers.dns-cloudflare.acme.dnsChallenge.delayBeforeCheck=90 # To delay DNS check and reduce LE hitrate
  104.     networks:
  105.       t2_proxy:
  106.      # ipv4_address: 192.168.90.254 # You can specify a static IP
  107.       # socket_proxy:
  108.     # networks:
  109.     #  - t2_proxy
  110.     ports:
  111.       - target: 80
  112.         published: 80
  113.         protocol: tcp
  114.         mode: host
  115.       - target: 443
  116.         published: 443
  117.         protocol: tcp
  118.         mode: host
  119.       #  - "8080:8080"
  120.       #- target: 8080 # insecure api wont work
  121.       #   published: 8080
  122.       #   protocol: tcp
  123.       #   mode: host
  124.     volumes:
  125.      - $DOCKERDIR/appdata/traefik2/rules/cloudserver:/rules # file provider directory
  126.       - /var/run/docker.sock:/var/run/docker.sock:ro # If you use Docker Socket Proxy, comment this line out
  127.       - $DOCKERDIR/appdata/traefik2/acme/acme.json:/acme.json # cert location - you must create this empty file and change permissions to 600
  128.       - $DOCKERDIR/logs/cloudserver/traefik:/logs # for fail2ban or crowdsec
  129.       - $DOCKERDIR/shared:/shared
  130.     environment:
  131.      - TZ=$TZ
  132.       - CF_API_EMAIL=$CLOUDFLARE_EMAIL
  133.       - CF_API_KEY=$CLOUDFLARE_API_KEY
  134.       - DOMAINNAME_CLOUD_SERVER # Passing the domain name to the traefik container to be able to use the variable in rules.
  135.     labels:
  136.      - "traefik.enable=true"
  137.       # HTTP-to-HTTPS Redirect
  138.       - "traefik.http.routers.http-catchall.entrypoints=http"
  139.       - "traefik.http.routers.http-catchall.rule=HostRegexp(`{host:.+}`)"
  140.       - "traefik.http.routers.http-catchall.middlewares=redirect-to-https"
  141.       - "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
  142.       # HTTP Routers
  143.       - "traefik.http.routers.traefik-rtr.entrypoints=https"
  144.       - "traefik.http.routers.traefik-rtr.rule=Host(`traefik.$DOMAINNAME_CLOUD_SERVER`)"
  145.       - "traefik.http.routers.traefik-rtr.tls=true" # Some people had 404s without this
  146.       # - "traefik.http.routers.traefik-rtr.tls.certresolver=dns-cloudflare" # Comment out this line after first run of traefik to force the use of wildcard certs
  147.       - "traefik.http.routers.traefik-rtr.tls.domains[0].main=$DOMAINNAME_CLOUD_SERVER"
  148.       - "traefik.http.routers.traefik-rtr.tls.domains[0].sans=*.$DOMAINNAME_CLOUD_SERVER"
  149.       # - "traefik.http.routers.traefik-rtr.tls.domains[1].main=$DOMAINNAME2" # Pulls main cert for second domain
  150.       # - "traefik.http.routers.traefik-rtr.tls.domains[1].sans=*.$DOMAINNAME2" # Pulls wildcard cert for second domain
  151.       ## Services - API
  152.       - "traefik.http.routers.traefik-rtr.service=api@internal"
  153.       ## Middlewares
  154.       - "traefik.http.routers.traefik-rtr.middlewares=middlewares-rate-limit@file,middlewares-https-redirectscheme@file,middlewares-secure-headers@file,middlewares-basic-auth@file,middlewares-compress@file"
  155.      
  156.  
  157.  
  158.   # Dozzle - Real-time Docker Log Viewer
  159.   dozzle:
  160.     image: amir20/dozzle:latest
  161.     container_name: dozzle
  162.     security_opt:
  163.      - no-new-privileges:true
  164.     restart: unless-stopped
  165.     networks:
  166.      - t2_proxy
  167.       # - socket_proxy
  168.     ports:
  169.      - "8082:8080"
  170.     #environment:
  171.       # DOZZLE_LEVEL: debug
  172.       # DOZZLE_TAILSIZE: 300
  173.       # DOZZLE_FILTER: "status=running"
  174.       # DOZZLE_FILTER: "label=log_me" # limits logs displayed to containers with this label
  175.       # DOCKER_HOST: tcp://socket-proxy:2375
  176.     volumes:
  177.      - /var/run/docker.sock:/var/run/docker.sock # Use Docker Socket Proxy instead for improved security
  178.     labels:
  179.      - "traefik.enable=true"
  180.       ## HTTP Routers
  181.       - "traefik.http.routers.dozzle-rtr.entrypoints=https"
  182.       - "traefik.http.routers.dozzle-rtr.rule=Host(`dozzle.$DOMAINNAME_CLOUD_SERVER`)"
  183.       ## Middlewares
  184.       - "traefik.http.routers.dozzle-rtr.middlewares=chain-basic-auth@file"
  185.       ## HTTP Services
  186.       - "traefik.http.routers.dozzle-rtr.service=dozzle-svc"
  187.       - "traefik.http.services.dozzle-svc.loadbalancer.server.port=8080"
  188.  
  189. # Portainer - WebUI for Containers
  190.   portainer:
  191.     <<: *common-keys-core # See EXTENSION FIELDS at the top
  192.     container_name: portainer
  193.     image: portainer/portainer-ee:latest
  194.     # command: -H unix:///var/run/docker.sock # Use Docker Socket Proxy and comment this line out, for improved security.
  195.     # command: -H tcp://socket-proxy:2375 # Use this instead, if you have Socket Proxy enabled.
  196.     networks:
  197.      - t2_proxy
  198.     ports: # Commented out because we are going to use Traefik to access portainer WebUI.
  199.     #  - "$PORTAINER_PORT:9000"
  200.       - 9000:9000
  201.     volumes:
  202.      - /var/run/docker.sock:/var/run/docker.sock:ro # Use Docker Socket Proxy and comment this line out, for improved security.
  203.       - $DOCKERDIR/appdata/portainer/data:/data # Change to local directory if you want to save/transfer config locally.
  204.     environment:
  205.      - TZ=$TZ
  206.     labels:
  207.      - "traefik.enable=true"
  208.       ## HTTP Routers
  209.       - "traefik.http.routers.portainer-rtr.entrypoints=https"
  210.       - "traefik.http.routers.portainer-rtr.rule=Host(`portainer.$DOMAINNAME_CLOUD_SERVER`)"
  211.       # - "traefik.http.routers.portainer-rtr.tls=true"
  212.       ## Middlewares
  213.       - "traefik.http.routers.portainer-rtr.middlewares=chain-basic-auth@file"
  214.       ## HTTP Services
  215.       - "traefik.http.routers.portainer-rtr.service=portainer-svc"
  216.       - "traefik.http.services.portainer-svc.loadbalancer.server.port=9000"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement