- Removed `install.sh` and moved Docker-related assets to `deploy/docker`. - Updated all Dockerfile references from `build/` to `deploy/docker/`. - Refactored paths in E2E tests, Makefile, and documentation for consistency with new directory structure. - Added `HAPROXY_STATS_CORS_ORIGIN` environment variable in `docker-compose.yml`.
82 lines
2.3 KiB
YAML
82 lines
2.3 KiB
YAML
# ==============================================================================
|
|
# EXAMPLE: Load Balancing with Multiple Container Replicas
|
|
# ==============================================================================
|
|
#
|
|
# WHAT THIS DEMONSTRATES:
|
|
# - Multiple container replicas behind a single domain
|
|
# - Round-robin load balancing across replicas
|
|
# - Domain redirect functionality
|
|
# - Custom port configuration
|
|
#
|
|
# REQUIREMENTS (run these first):
|
|
# ```bash
|
|
# # No special requirements - this example runs on localhost:19901
|
|
# ```
|
|
#
|
|
# HOW TO START:
|
|
# ```bash
|
|
# docker compose -f docker-compose-multi-containers.yml up -d
|
|
# ```
|
|
#
|
|
# HOW TO VERIFY IT'S WORKING:
|
|
# ```bash
|
|
# # Test load balancing - hostname should alternate between containers
|
|
# curl -H "Host: www.helloworld.com" localhost:19901
|
|
# # Expected: Container ID (e.g., f6d8d45b7411)
|
|
# curl -H "Host: www.helloworld.com" localhost:19901
|
|
# # Expected: Different container ID (e.g., 59b213cb8592)
|
|
#
|
|
# # Test domain redirect
|
|
# curl -I -H "Host: google.helloworld.com" localhost:19901
|
|
# # Expected: HTTP/1.1 301 Moved Permanently, Location: www.google.com/
|
|
#
|
|
# # View HAProxy stats
|
|
# # URL: http://localhost:1936
|
|
# # Username: admin
|
|
# # Password: password
|
|
# # You should see 2 backend servers
|
|
# ```
|
|
#
|
|
# CLEAN UP:
|
|
# ```bash
|
|
# docker compose -f docker-compose-multi-containers.yml down
|
|
# ```
|
|
#
|
|
# ==============================================================================
|
|
|
|
services:
|
|
haproxy:
|
|
build:
|
|
context: ../../
|
|
dockerfile: deploy/docker/Dockerfile
|
|
image: byjg/easy-haproxy:local
|
|
volumes:
|
|
- /var/run/docker.sock:/var/run/docker.sock
|
|
healthcheck:
|
|
test: ["CMD", "curl", "-f", "-u", "admin:password", "http://localhost:1936"]
|
|
interval: 10s
|
|
timeout: 5s
|
|
start_period: 30s
|
|
retries: 3
|
|
environment:
|
|
EASYHAPROXY_DISCOVER: docker
|
|
HAPROXY_CUSTOMERRORS: "true"
|
|
HAPROXY_USERNAME: admin
|
|
HAPROXY_PASSWORD: password
|
|
HAPROXY_STATS_PORT: 1936
|
|
ports:
|
|
- 19901:19901
|
|
- 1936:1936
|
|
|
|
|
|
nginx:
|
|
#image: nginx
|
|
image: stenote/nginx-hostname
|
|
deploy:
|
|
replicas: 2
|
|
labels:
|
|
easyhaproxy.http.redirect: '{"google.helloworld.com": "www.google.com"}'
|
|
easyhaproxy.http.host: www.helloworld.com
|
|
easyhaproxy.http.port: 19901
|
|
easyhaproxy.http.localport: 80
|
|
|