Skip to content

Instantly share code, notes, and snippets.

@hmldd
Last active October 30, 2019 06:49
Show Gist options
  • Save hmldd/53b01d6ae4d39b81c9267a7d9e1cf818 to your computer and use it in GitHub Desktop.
Save hmldd/53b01d6ae4d39b81c9267a7d9e1cf818 to your computer and use it in GitHub Desktop.
简单的 traefik docker compose 配置文件,整理自 traefik 官方 Quick start。详情:https://docs.traefik.io/getting-started/quick-start/
version: '3'
services:
gateway:
# 官方最新的 traefik docker 镜像
image: traefik:latest
# 停止后重新启动
restart: unless-stopped
# 开启 traefik web UI 界面并监听 docker
command:
- --api.insecure=true
- --providers.docker
ports:
# HTTP 端口
- "80:80"
# Web UI 端口(通过 --api.insecure=true 开启)
- "8080:8080"
volumes:
# 绑定 docker.sock 使 traefik 能够监听 docker 事件
- /var/run/docker.sock:/var/run/docker.sock
whoami:
image: containous/whoami
# 通过 IP 地址或域名提供一个容器的服务
labels:
- "traefik.http.routers.whoami.rule=Host(`whoami.docker.localhost`)"
nginx:
image: nginx:latest
restart: unless-stopped
# 绑定 web 文件目录和 nginx 配置目录
volumes:
- ./web:/web:ro
- ./config/nginx/vhost.conf:/etc/nginx/conf.d/vhost.conf
# 解决 docker 容器中的 bash 前台执行外部命令时不接收 signal 的问题
command: "/bin/sh -c 'while :; do sleep 6h; nginx -s reload; done & exec nginx -g \"daemon off;\"'"
# 通过 IP 地址或域名访问
labels:
- "traefik.http.routers.nginx.rule=Host(`web.docker.localhost`)"
# Nginx静态文件服务器配置
server {
server_name web.docker.localhost;
root /web;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment