Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Commit d031529

Browse files
author
Feng Honglin
committed
Merge pull request #46 from dgilling/patch-1
Update README.rd, Add missing information on ADDITONAL_SERVICES for S…
2 parents f3fb89c + a6a7750 commit d031529

1 file changed

Lines changed: 36 additions & 2 deletions

File tree

README.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Legacy link refers to the link created before docker 1.10, and the link created
7676
**Note**: Any link alias sharing the same prefix and followed by "-/_" with an integer is considered to be from the same service. For example: `web-1` and `web-2` belong to service `web`, `app_1` and `app_2` are from service `app`, but `app1` and `web2` are from different services.
7777

7878

79-
### Running with Docker Compose v2(new links, compatible with Docker Swarm)
79+
### Running with Docker Compose v2(new links)
8080

8181
Docker Compose 1.6 supports a new format of the compose file. In the new version(v2), the old link that injects environment variables is deprecated.
8282

@@ -86,7 +86,6 @@ Similar to using legacy links, here list some differences that you need to notic
8686
- A link is required in order to ensure that dockercloud/haproxy is aware of which service it needs to balance, although links are not needed for service discovery since docker 1.10. Linked aliases are not required.
8787
- DO not overwrite `HOSTNAME` environment variable in `dockercloud/haproxy container`.
8888
- As it is the case on Docker Cloud, auto reconfiguration is supported when the linked services scales or/and the linked container starts/stops.
89-
- This image is also compatible with Docker Swarm, and supports the docker native `overlay` network across multi-hosts.
9089

9190
##### example of docker-compose.yml running in linux:
9291

@@ -124,6 +123,41 @@ Similar to using legacy links, here list some differences that you need to notic
124123

125124
Once the stack is up, you can scale the web service using `docker-compose scale web=3`. dockercloud/haproxy will automatically reload its configuration.
126125

126+
#### Running with Docker Compose v2 and Swarm (using envvar)
127+
When using links like previous section, the Docker Swarm scheduler can be too restrictive.
128+
Even with overlay network, swarm (As of 1.1.0) will attempt to schedule haproxy on the same node as the linked service due to legacy links behavior.
129+
This can cause unwanted scheduling patterns or errors such as "Unable to find a node fulfilling all dependencies..."
130+
131+
Since Compose V2 allows discovery through the service names, Dockercloud haproxy only needs the links to indentify which service should be load balanced.
132+
133+
A second option is to use the `ADDITIONAL_SERVICES` variable for indentification of services.
134+
135+
- Set the `ADDITIONAL_SERVICES` env variable to your linked services.
136+
- You also want to set depends_on to ensure the web service is started before haproxy so that the hostname can be resolved. This controls scheduling order but not location.
137+
- The container still needs access to the docker daemon to get load balanced containers' configs.
138+
- If any trouble with haproxy not updating the config, try running reload.sh or set the `DEBUG` envvar.
139+
- This image is also compatible with Docker Swarm, and supports the docker native `overlay` network across multi-hosts.
140+
141+
##### example of docker-compose.yml in 'project_dir' directory running in linux:
142+
143+
version: '2'
144+
services:
145+
web:
146+
image: dockercloud/hello-world
147+
blog:
148+
image: dockercloud/hello-world
149+
lb:
150+
image: dockercloud/haproxy
151+
depends_on:
152+
- web
153+
- blog
154+
environment:
155+
- ADDITIONAL_SERVICES=project_dir:web,project_dir:blog
156+
volumes:
157+
- /var/run/docker.sock:/var/run/docker.sock
158+
ports:
159+
- 80:80
160+
127161
## Configuration
128162

129163
### Global and default settings of HAProxy###

0 commit comments

Comments
 (0)