Skip to content

Commit

Permalink
[DCK] Add traefik2 documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
josep-tecnativa committed Jun 13, 2024
1 parent e2f4efd commit ce95061
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 2 deletions.
90 changes: 88 additions & 2 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ version: "2.1"

services:
proxy:
image: docker.io/traefik:1.6-alpine
image: docker.io/traefik:1.7-alpine
networks:
shared:
private:
Expand Down Expand Up @@ -257,7 +257,93 @@ volumes:
<details>
<summary>Traefik v2 docker compose</summary>
![TODO](https://media.giphy.com/media/26gspO0c90QDHEQQ8/giphy.gif)
```yaml
version: "2.4"
services:
proxy:
image: traefik:2.4
networks:
shared:
aliases: []
private:
public:
volumes:
- acme:/etc/traefik/acme:rw,Z
ports:
- 80:80
- 443:443
depends_on:
- dockersocket
restart: unless-stopped
tty: true
command:
- "--entrypoints.web-insecure.address=:80"
- "--entrypoints.web-main.transport.respondingTimeouts.idleTimeout=60s"
- "--entrypoints.web-main.http.middlewares=global-error-502@docker"
- "--log.level=info"
- "--providers.docker.endpoint=http://dockersocket:2375"
- "--providers.docker.exposedbydefault=false"
- "--providers.docker.network=inverseproxy_shared"
- "--providers.docker=true"
- "--entrypoints.web-main.address=:443"
- "--entrypoints.web-main.http.tls.certResolver=letsencrypt"
- "--certificatesresolvers.letsencrypt.acme.caserver=https://acme-v02.api.letsencrypt.org/directory"
- "--certificatesresolvers.letsencrypt.acme.email=alerts@example.com"
- "--certificatesresolvers.letsencrypt.acme.storage=/etc/traefik/acme/acme-v2.json"
- "--entrypoints.web-insecure.http.redirections.entryPoint.to=web-main"
- "--entrypoints.web-insecure.http.redirections.entryPoint.scheme=https"
- "--certificatesresolvers.letsencrypt.acme.httpchallenge.entrypoint=web-insecure"
dockersocket:
image: tecnativa/docker-socket-proxy
privileged: true
networks:
private:
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
environment:
CONTAINERS: 1
NETWORKS: 1
SERVICES: 1
SWARM: 1
TASKS: 1
restart: unless-stopped
error-handling:
image: nginx:alpine
restart: unless-stopped
networks:
- shared
volumes:
- error-handling-config:/etc/nginx/conf.d/
- error-handling-data:/usr/share/nginx/html/
labels:
traefik.docker.network: inverseproxy_shared
traefik.enable: "true"
traefik.http.routers.error-handling.rule: HostRegexp(`{any:.+}`)
traefik.http.routers.error-handling.entrypoints: web-main
traefik.http.routers.error-handling.priority: 1
traefik.http.routers.error-handling.service: global-error-handler
traefik.http.routers.error-handling.middlewares: global-error-502
traefik.http.middlewares.global-error-502.errors.status: 502
traefik.http.middlewares.global-error-502.errors.service: global-error-handler
traefik.http.middlewares.global-error-502.errors.query: "/{status}.html"
traefik.http.services.global-error-handler.loadbalancer.server.port: 80
networks:
shared:
internal: true
driver_opts:
encrypted: 1
private:
internal: true
driver_opts:
encrypted: 1
public:
driver_opts:
encrypted: 1
volumes:
acme:
error-handling-config:
error-handling-data:
```
</details>
Expand Down
12 changes: 12 additions & 0 deletions tests/test_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,20 @@ def test_multiple_domains(
else:
# main0, no TLS
response = requests.get(f"http://main0.{base_path}")
print(
f"main1.{base_path} Response Status: {response.status_code}, URL: {response.url}"
)
print(f"Response Headers: {response.headers}")
assert response.ok
assert response.url == f"http://main0.{base_path}"
assert response.headers["X-Robots-Tag"] == "noindex, nofollow"
# alt0 and alt1, no TLS
for alt_num in range(2):
response = requests.get(f"http://alt{alt_num}.main0.{base_path}")
print(
f"main1.{base_path} Response Status: {response.status_code}, URL: {response.url}"
)
print(f"Response Headers: {response.headers}")
assert response.ok
assert response.url == f"http://main0.{base_path}"
assert response.history[0].status_code == 302
Expand Down Expand Up @@ -168,6 +176,10 @@ def test_multiple_domains(
f"http://alt{alt_num}.main1.{base_domain}/web/database/selector",
verify=False,
)
print(
f"main1.{base_path} Response Status: {response.status_code}, URL: {response.url}"
)
print(f"Response Headers: {response.headers}")
assert response.ok
assert (
response.url == f"https://main1.{base_domain}/web/database/selector"
Expand Down

0 comments on commit ce95061

Please sign in to comment.