Skip to content

Commit 3c263d6

Browse files
committed
Path rewrite (fixes #18)
1 parent c52f8e6 commit 3c263d6

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

articles/swarm-mode-listener.md

+24-23
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* [Automatically Reconfiguring the Proxy](#automatically-reconfiguring-the-proxy)
77
* [Removing a Service From the Proxy](#removing-a-service-from-the-proxy)
88
* [Scaling the Proxy](#scaling-the-proxy)
9+
* [Rewriting Paths](#rewriting-paths)
910
* [Basic Authentication](#basic-authentication)
1011

1112
* [Global Authentication](#global-authentication)
@@ -286,34 +287,12 @@ curl -i $(docker-machine ip node-1)/demo/hello
286287

287288
Since Docker's networking (`routing mesh`) is performing load balancing, each of those requests is sent to a different proxy instance. Each was forwarded to the `go-demo` service endpoint, Docker networking did load balancing and resent it to one of the `go-demo` instances. As a result, all requests returned status *200 OK* proving that the combination of the proxy and the listener indeed works. All three instances of the proxy were reconfigured.
288289

289-
Let's remove the `go-demo` service before we proceed with explanation of the flow.
290+
Let's remove the `go-demo` service before we proceed with an example of rewriting paths.
290291

291292
```bash
292293
docker service rm go-demo
293294
```
294295

295-
Before you start using `Docker Flow: Proxy`, you might want to get a better understanding of the flow of a request.
296-
297-
## The Flow Explained
298-
299-
We'll go over the flow of a request to one of the services in the Swarm cluster.
300-
301-
A user or a service sends a request to our DNS (e.g. *acme.com*). The request is usually HTTP on the port `80` or HTTPS on the port `443`.
302-
303-
DNS resolves the domain to one of the servers inside the cluster. We do not need to register all the nodes. A few is enough (more than one in the case of a failure).
304-
305-
The Docker's routing mesh inspects which containers are running on a given port and re-sends the request to one of the instances of the proxy. It uses round robin load balancing so that all instances share the load (more or less) equally.
306-
307-
The proxy inspects the request path (e.g. `/demo/hello`) and sends it the end-point with the same name as the destination service (e.g. `go-demo`). Please note that for this to work, both the proxy and the destination service need to belong to the same network (e.g. `proxy`). The proxy changes the port to the one of the destination service (e.g. `8080`).
308-
309-
The proxy network performs load balancing among all the instances of the destination service, and re-sends the request to one of them.
310-
311-
The whole process sounds complicated (it actually is from the engineering point of view). But, as a user, all this is transparent.
312-
313-
One of the important things to note is that, with a system like this, everything can be fully dynamic. Before the new Swarm introduced in Docker 1.12, we would need to run our proxy instances on predefined nodes and make sure that they are registered as DNS records. With the new routing mesh, it does not matter whether the proxy runs on a node registered in DNS. It's enough to hit any of the servers, and the routing mesh will make sure that it reaches one of the proxy instances.
314-
315-
A similar logic is used for the destination services. The proxy does not need to do load balancing. Docker networking does that for us. The only thing it needs is the name of the service and that both belong to the same network. As a result, there is no need to reconfigure the proxy every time a new release is made or when a service is scaled.
316-
317296
## Rewriting Paths
318297

319298
In some cases, you might want to rewrite the path of the incoming request before forwarding it to the destination service. We can do that using request parameters `reqRepSearch` and `reqRepReplace`.
@@ -685,6 +664,28 @@ Please note that you are not limited to a single certificate. You can send multi
685664

686665
Now you can secure your proxy communication with SSL certificates. Unless you already have a certificate, purchase it or get it for free from [Let's Encrypt](https://letsencrypt.org/). The only thing left is for you to send a request to the proxy to include the certificate and try it out with your domain.
687666

667+
Before you start using `Docker Flow: Proxy`, you might want to get a better understanding of the flow of a request.
668+
669+
## The Flow Explained
670+
671+
We'll go over the flow of a request to one of the services in the Swarm cluster.
672+
673+
A user or a service sends a request to our DNS (e.g. *acme.com*). The request is usually HTTP on the port `80` or HTTPS on the port `443`.
674+
675+
DNS resolves the domain to one of the servers inside the cluster. We do not need to register all the nodes. A few is enough (more than one in the case of a failure).
676+
677+
The Docker's routing mesh inspects which containers are running on a given port and re-sends the request to one of the instances of the proxy. It uses round robin load balancing so that all instances share the load (more or less) equally.
678+
679+
The proxy inspects the request path (e.g. `/demo/hello`) and sends it the end-point with the same name as the destination service (e.g. `go-demo`). Please note that for this to work, both the proxy and the destination service need to belong to the same network (e.g. `proxy`). The proxy changes the port to the one of the destination service (e.g. `8080`).
680+
681+
The proxy network performs load balancing among all the instances of the destination service, and re-sends the request to one of them.
682+
683+
The whole process sounds complicated (it actually is from the engineering point of view). But, as a user, all this is transparent.
684+
685+
One of the important things to note is that, with a system like this, everything can be fully dynamic. Before the new Swarm introduced in Docker 1.12, we would need to run our proxy instances on predefined nodes and make sure that they are registered as DNS records. With the new routing mesh, it does not matter whether the proxy runs on a node registered in DNS. It's enough to hit any of the servers, and the routing mesh will make sure that it reaches one of the proxy instances.
686+
687+
A similar logic is used for the destination services. The proxy does not need to do load balancing. Docker networking does that for us. The only thing it needs is the name of the service and that both belong to the same network. As a result, there is no need to reconfigure the proxy every time a new release is made or when a service is scaled.
688+
688689
## Usage
689690

690691
Please explore [Usage](../README.md#usage) for more information.

0 commit comments

Comments
 (0)