반응형
traefik을 사용하는 도커 컨테이너 리버스 프록시(docker container reverse proxy)
docker-compose.yml 기본 예제
docker-compose.yml 편집
vim docker-compose.yml
version: "3.3"
services:
traefik:
image: "traefik:v2.9"
container_name: "traefik"
command:
#- "--log.level=DEBUG"
- "--api.insecure=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:80"
ports:
- "80:80"
- "8080:8080"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
whoami:
image: "traefik/whoami"
container_name: "simple-service"
labels:
- "traefik.enable=true"
- "traefik.http.routers.whoami.rule=Host(`whoami.localhost`)"
- "traefik.http.routers.whoami.entrypoints=web"
docker-compose up -d
docker-compose ps
$ docker-compose ps
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
simple-service traefik/whoami "/whoami" whoami 4 minutes ago Up 4 minutes 80/tcp
traefik traefik:v2.9 "/entrypoint.sh --ap…" traefik 4 minutes ago Up 4 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp
웹 브라우저
- http://192.168.0.51:8080
Quick Start
docker-compose.yml 편집
vim docker-compose.yml
version: '3.9'
services:
traefik:
image: traefik:v2.9
container_name: traefik
command:
- --api.insecure=true
- --providers.docker
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
ports:
- 80:80
- 8080:8080
whoami:
image: traefik/whoami
labels:
- traefik.http.routers.whoami.rule=Host(`whoami.docker.localhost`)
docker-compose up -d
docker-compose ps
$ docker-compose ps
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
docker-traefik-whoami-1 traefik/whoami "/whoami" whoami 11 seconds ago Up 10 seconds 80/tcp
traefik traefik:v2.9 "/entrypoint.sh --ap…" traefik 11 seconds ago Up 10 seconds 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp
curl -H Host:whoami.docker.localhost http://127.0.0.1
$ curl -H Host:whoami.docker.localhost http://127.0.0.1
Hostname: ac51c3f7939b
IP: 127.0.0.1
IP: 172.25.0.2
RemoteAddr: 172.25.0.3:44900
GET / HTTP/1.1
Host: whoami.docker.localhost
User-Agent: curl/7.81.0
Accept: */*
Accept-Encoding: gzip
X-Forwarded-For: 172.25.0.1
X-Forwarded-Host: whoami.docker.localhost
X-Forwarded-Port: 80
X-Forwarded-Proto: http
X-Forwarded-Server: a1bdb1a9a962
X-Real-Ip: 172.25.0.1
whoami 컨테이너를 하나 더 실행시킵니다.
docker-compose up -d --scale whoami=2
$ docker-compose ps
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
docker-traefik-whoami-1 traefik/whoami "/whoami" whoami 13 seconds ago Up 13 seconds 80/tcp
docker-traefik-whoami-2 traefik/whoami "/whoami" whoami 14 seconds ago Up 12 seconds 80/tcp
traefik traefik:v2.9 "/entrypoint.sh --ap…" traefik 2 minutes ago Up 2 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp
curl -H Host:whoami.docker.localhost http://127.0.0.1
$ curl -H Host:whoami.docker.localhost http://127.0.0.1
Hostname: f595e0603765
IP: 127.0.0.1
IP: 172.25.0.2
RemoteAddr: 172.25.0.3:43366
GET / HTTP/1.1
Host: whoami.docker.localhost
...
$ curl -H Host:whoami.docker.localhost http://127.0.0.1
Hostname: c719743b21fd
IP: 127.0.0.1
IP: 172.25.0.4
RemoteAddr: 172.25.0.3:36454
GET / HTTP/1.1
Host: whoami.docker.localhost
...
참고URL
- Quick Start : https://doc.traefik.io/traefik/getting-started/quick-start/
- traefiklabs(user guides) : https://doc.traefik.io/traefik/user-guides/docker-compose/basic-example/
- traefik docs : https://doc.traefik.io/traefik/getting-started/configuration-overview/
- Traefik & Docker : https://doc.traefik.io/traefik/providers/docker
- Let's Encrypt : https://doc.traefik.io/traefik/https/acme/#providers
- docker hub : https://registry.hub.docker.com/_/traefik/tags
- Traefik Proxy with HTTPS: https://dockerswarm.rocks/traefik/
728x90
반응형
'리눅스' 카테고리의 다른 글
우분투에서 Pacemaker와 Corosync를 사용해 고가용성 클러스터를 구성하는 방법 (0) | 2023.01.31 |
---|---|
[리눅스] envoy를 사용하는 도커 컨테이너 리버스 프록시(docker container reverse proxy) (0) | 2023.01.29 |
[리눅스] nomad cluster 구성(install nomad cluster) (0) | 2023.01.27 |
[리눅스] nomad 설치(install nomad) (0) | 2023.01.27 |
[리눅스] consul 서비스 등록 (0) | 2023.01.27 |