Application redirects

Estimated reading time: 1 minute

Once the layer 7 routing solution is enabled, you can start using it in your swarm services. In this example we’ll deploy a simple service that can be reached at We’ll also redirect requests to to that service.

To do that, create a docker-compose.yml file with:

version: "3.2"

    image: ehazlett/docker-demo
      replicas: 1
      labels:, demo-network 8080,
      - demo-network

    driver: overlay

Note that the demo service has labels to signal that traffic for both and should be routed to this service. There’s also a label indicating that all traffic directed to should be redirected to

Set up your CLI client with a UCP client bundle, and deploy the service:

docker stack deploy --compose-file docker-compose.yml demo

You can also use the CLI to test if the redirect is working, by running:

curl --head --header "Host:" http://<ucp-ip>:<http-port>

You should see something like:

HTTP/1.1 302 Moved Temporarily
Server: nginx/1.13.8
Date: Thu, 29 Mar 2018 23:16:46 GMT
Content-Type: text/html
Content-Length: 161
Connection: keep-alive

You can also test that the redirect works from your browser. For that, you need to make sure you add entries for both and to your /etc/hosts file, mapping them to the IP address of a UCP node.

routing, proxy, redirects