2.4 KiB
2.4 KiB
| sidebar_position | sidebar_label |
|---|---|
| 2 | Docker Swarm |
Docker Swarm
EasyHAProxy inspects Docker Swarm services, reads their labels, and configures HAProxy automatically across all nodes.
:::tip Docker Swarm Advantages
- Container Discovery: Docker Swarm facilitates the discovery of containers within the cluster.
- Remote Node Management: Manage containers across multiple nodes while EasyHAProxy configures HAProxy seamlessly. :::
:::warning Limitations
- You cannot mix Docker containers with Swarm containers.
- This method does not work with containers that use the
--network=hostoption. See limitations for details. :::
Step 1 — Create an overlay network
docker network create -d overlay --attachable easyhaproxy
Step 2 — Deploy EasyHAProxy as a Swarm stack
services:
haproxy:
image: byjg/easy-haproxy:6.1.1
volumes:
- /var/run/docker.sock:/var/run/docker.sock
deploy:
replicas: 1
environment:
EASYHAPROXY_DISCOVER: swarm
EASYHAPROXY_SSL_MODE: "loose"
HAPROXY_CUSTOMERRORS: "true"
HAPROXY_USERNAME: admin
HAPROXY_PASSWORD: password
HAPROXY_STATS_PORT: 1936
ports:
- "80:80/tcp"
- "443:443/tcp"
- "1936:1936/tcp"
networks:
- easyhaproxy
networks:
easyhaproxy:
external: true
docker stack deploy --compose-file docker-compose.yml easyhaproxy
:::danger Single Replica Only Do not add more than one replica for EasyHAProxy. To understand why, see the limitations page. :::
Step 3 — Label your service
services:
container:
image: my/image:tag
deploy:
replicas: 1
labels:
easyhaproxy.http.host: host1.local
easyhaproxy.http.port: 80
easyhaproxy.http.localport: 8080
networks:
- easyhaproxy
networks:
easyhaproxy:
external: true
EasyHAProxy detects this service automatically and routes traffic from host1.local:80 to your container. You do not need to expose any container ports.
Step 4 — Verify
curl http://host1.local
Full options
- Container label reference — all available labels
- Environment variable reference — configure EasyHAProxy behavior
- Docker guide — more detailed Docker examples