我怎样才能让 traefik 在我的云架构上工作?
How can I get traefik to work on my cloud architecture?
好的,所以在我的 EC2 上花了一天时间使用 Traefik 和 Docker 设置,但似乎没有按照文档中的描述工作。我可以获得 Whoami 示例 运行 但这并不能真正说明我在寻找什么?
对于我的示例,我有三个 AWS API 网关端点,我需要将它们指向我的 EC2 IP 地址,该地址由我的 Traefik 前端设置路由,然后使用一些后端?我仍然不确定要使用哪种后端。
我似乎找不到一个很好的 YAML 示例来清楚地说明适合我的目的和需要的内容。
谁能指出我正确的方向?任何好的例子 Docker YAML 例子,为我下面的例子设置的配置?谢谢!
我已将 this 文章作为使用 traefik 提供 docker 安装的指南。
编辑:在此之前,创建一个名为代理的 docker 网络。
$ docker network create proxy
version: '3'
networks:
proxy:
external: true
internal:
external: false
services:
reverse-proxy:
image: traefik:latest # The official Traefik docker image
command: --api --docker --acme.email="your-email" # Enables the web UI and tells Træfik to listen to docker
restart: always
labels:
- traefik.frontend.rule=Host:traefik.your-server.net
- traefik.port=8080
networks:
- proxy
ports:
- "80:80" # The HTTP port
- "8080:8080" # The Web UI (enabled by --api)
- "443:443"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- $PWD/traefik.toml:/etc/traefik/traefik.toml
- $PWD/acme.json:/acme.json
db:
image: mariadb:10.3
restart: always
environment:
MYSQL_ROOT_PASSWORD: r00tPassw0rd
volumes:
- vol-db:/var/lib/mysql
networks:
- internal # since you do not need to expose this via traefik, so just set it to internal network
labels:
- traefik.enable=false
api-1:
image: your-api-image
restart: always
networks:
- internal
- proxy
labels:
- "traefik.docker.network=proxy"
- "traefik.enable=true"
- "traefik.frontend.rule=Host:api1.yourdomain.com"
- "traefik.port=80"
- "traefik.protocol=http"
api-2:
image: your-api-2-image
restart: always
networks:
- internal
- proxy
labels:
- "traefik.docker.network=proxy"
- "traefik.enable=true"
- "traefik.frontend.rule=Host:api2.yourdomain.com"
- "traefik.port=80"
- "traefik.protocol=http"
注意:如果您还想启用 SSL,请使用此选项。请注意,这可能不适用于本地服务器,因为 letsencrypt 无法完成 SSL 设置的挑战。
创建一个空白文件 acme.json 并将其权限设置为 0600
touch acme.json
chmod 0600 acme.json
设置完所有内容后,
docker-compose config
# 这是可选的。
然后,
docker-compose up
我已经发布了我的 traefik.toml
here
希望对您有所帮助。
如果您遇到任何问题,请告诉我。
此致,
库沙尔。
好的,所以在我的 EC2 上花了一天时间使用 Traefik 和 Docker 设置,但似乎没有按照文档中的描述工作。我可以获得 Whoami 示例 运行 但这并不能真正说明我在寻找什么?
对于我的示例,我有三个 AWS API 网关端点,我需要将它们指向我的 EC2 IP 地址,该地址由我的 Traefik 前端设置路由,然后使用一些后端?我仍然不确定要使用哪种后端。
我似乎找不到一个很好的 YAML 示例来清楚地说明适合我的目的和需要的内容。
谁能指出我正确的方向?任何好的例子 Docker YAML 例子,为我下面的例子设置的配置?谢谢!
我已将 this 文章作为使用 traefik 提供 docker 安装的指南。
编辑:在此之前,创建一个名为代理的 docker 网络。
$ docker network create proxy
version: '3'
networks:
proxy:
external: true
internal:
external: false
services:
reverse-proxy:
image: traefik:latest # The official Traefik docker image
command: --api --docker --acme.email="your-email" # Enables the web UI and tells Træfik to listen to docker
restart: always
labels:
- traefik.frontend.rule=Host:traefik.your-server.net
- traefik.port=8080
networks:
- proxy
ports:
- "80:80" # The HTTP port
- "8080:8080" # The Web UI (enabled by --api)
- "443:443"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- $PWD/traefik.toml:/etc/traefik/traefik.toml
- $PWD/acme.json:/acme.json
db:
image: mariadb:10.3
restart: always
environment:
MYSQL_ROOT_PASSWORD: r00tPassw0rd
volumes:
- vol-db:/var/lib/mysql
networks:
- internal # since you do not need to expose this via traefik, so just set it to internal network
labels:
- traefik.enable=false
api-1:
image: your-api-image
restart: always
networks:
- internal
- proxy
labels:
- "traefik.docker.network=proxy"
- "traefik.enable=true"
- "traefik.frontend.rule=Host:api1.yourdomain.com"
- "traefik.port=80"
- "traefik.protocol=http"
api-2:
image: your-api-2-image
restart: always
networks:
- internal
- proxy
labels:
- "traefik.docker.network=proxy"
- "traefik.enable=true"
- "traefik.frontend.rule=Host:api2.yourdomain.com"
- "traefik.port=80"
- "traefik.protocol=http"
注意:如果您还想启用 SSL,请使用此选项。请注意,这可能不适用于本地服务器,因为 letsencrypt 无法完成 SSL 设置的挑战。 创建一个空白文件 acme.json 并将其权限设置为 0600
touch acme.json
chmod 0600 acme.json
设置完所有内容后,
docker-compose config
# 这是可选的。
然后,
docker-compose up
我已经发布了我的 traefik.toml
here
希望对您有所帮助。 如果您遇到任何问题,请告诉我。
此致,
库沙尔。