<p>I can't tell exactly what you are trying, it looks like you might just not have Traefik and the services on the same network.</p>
<p>Its also helpful to have a domain that's going to resolve to 127.0.0.1 on wildcard queries.</p>
<p>This might be a valuable starting point as a working example.</p>
<pre class="lang-yaml prettyprint-override"><code>networks:
  traefik:
    name: demo_traefik

services:

  proxy:
    image: traefik:latest
    command: &gt;
      --accesslog=true
      --api.insecure=true
      --log.level=DEBUG
      --providers.docker=true
      --providers.docker.network=demo_traefik
    ports:
    - &quot;80:80&quot;
    - &quot;8080:8080&quot;
    networks:
    - traefik
    volumes:
    - /var/run/docker.sock:/var/run/docker.sock
    labels:
      traefik.http.routers.demo_traefik.rule: Host(`traefik.localtest.me`)
      traefik.http.services.demo_traefik.loadbalancer.server.port: 8080

  example:
    image: nginx
    networks:
    - traefik
    scale: 4
    labels:
      traefik.http.routers.demo_nginx.rule: Host(`example.localtest.me`)
      traefik.http.services.demo_nginx.loadbalancer.server.port: 80

  whoami:
    image: traefik/whoami
    networks:
    - traefik
    labels:
      traefik.http.middlewares.whoami_strip.stripprefix.prefixes: /whoami
      traefik.http.routers.whoami.rule: Host(`example.localtest.me`) &amp;&amp; PathPrefix(`/whoami`)
      traefik.http.routers.whoami.middlewares: whoami_strip
</code></pre>
<p><code>docker compose up</code> and then visit <a href="http://example.localtest.me/whoami" rel="nofollow noreferrer">http://example.localtest.me/whoami</a> in your browser.</p>

CC BY-SA 4.0
2022-11-29T06:05:46.460Z
2022-11-29T06:17:03.050Z
2022-11-29T06:17:03.050Z
Chris Becke
<p>I'm trying to use Traefik to route to a number of services all running using docker-compose. What I'd like to do is access each service with a prefix, eg: 10.20.30.40/u10/xyz and 10.20.30.40/a10/abc  instead of  10.20.30.40:8000/xyz and 10.20.30.40:8001/abc.</p>
<p>I have a `docker-compose.yml file where I'm starting my services a10,u10,x10, mongo,mosquitto and all are exposed on their own ports - this works.  I'm now stuck with the correct parameters for Traefik.  You can see some of the attempts and commenting out of parameters.</p>
<p>The services a10,u10 etc should only be accessible using a prefix and all over port 80. Load balancing should be possible, eg:  <code>docker-compose -f dc.yml --scale u10=3 --scale a10=5</code></p>
<p>When I run this if I try on my local machine:  <a href="http://127.0.0.1/u10/somepage.html" rel="nofollow noreferrer">http://127.0.0.1/u10/somepage.html</a> I get a gateway timeout error, or, if I don't try using --scale then I'll get a 404.</p>
<p>Internally these services communicate with each other over the specified ports (REST) without the prefix and this works internally.</p>
<pre class="lang-yaml prettyprint-override"><code>version: &quot;3&quot;
services:
   reverse-proxy:
     image: traefik:v2.9
     command:
       - &quot;--log.level=DEBUG&quot;
       - &quot;--api.insecure=true&quot;
       - &quot;--providers.docker=true&quot;
       - &quot;--providers.docker.exposedByDefault=true&quot;
       - &quot;--entrypoints.web.address=:80&quot;
       - &quot;--accesslog=true&quot;
     ports:
       - &quot;80:80&quot;
       - &quot;8080:8080&quot;
     volumes:
       - /var/run/docker.sock:/var/run/docker.sock

   u10:
     image: &quot;u10&quot;
#     container_name: u10     
#     ports:
#       - 8540:8540                           # !!!
     depends_on:
       - messagebus
     restart: always
     networks:
      - attestationnetwork
     volumes:
      - ./a10.conf:/etc/a10.conf      # !!!
     labels:
       - &quot;traefik.enable=true&quot;
 #      - &quot;traefik.port=8540&quot;
       - &quot;traefik.docker.network=my-internal-network&quot;
       - &quot;traefik.http.routers.u10.rule=PathPrefix(`/u10`)&quot;
       - &quot;traefik.http.routers.u10.entrypoints=web&quot;
       - &quot;traefik.http.routers.u10.middlewares=u10&quot;
       - &quot;traefik.http.middlewares.u10.stripprefix.prefixes=/u10&quot; 
       - &quot;traefik.http.middlewares.u10.stripprefix.forceSlash=false&quot;
       - &quot;traefik.http.routers.u10.service=u10&quot;       
       - &quot;traefik.http.services.u10.loadbalancer.server.port=8540&quot;

networks:
   my-internal-network:
     driver: bridge
</code></pre>

<docker><docker-compose><networking><traefik>
Port forwarding rules with Traefik and Docker.Compose
user3166273
# Port forwarding rules with Traefik and Docker.Compose

(Asked by: username_0 on 2022-11-20)

I'm trying to use Traefik to route to a number of services all running using docker-compose. What I'd like to do is access each service with a prefix, eg: 10.20.30.40/u10/xyz and 10.20.30.40/a10/abc  instead of  10.20.30.40:8000/xyz and 10.20.30.40:8001/abc.
I have a `docker-compose.yml file where I'm starting my services a10,u10,x10, mongo,mosquitto and all are exposed on their own ports - this works.  I'm now stuck with the correct parameters for Traefik.  You can see some of the attempts and commenting out of parameters.
The services a10,u10 etc should only be accessible using a prefix and all over port 80. Load balancing should be possible, eg:  docker-compose -f dc.yml --scale u10=3 --scale a10=5
When I run this if I try on my local machine:  http://127.0.0.1/u10/somepage.html I get a gateway timeout error, or, if I don't try using --scale then I'll get a 404.
Internally these services communicate with each other over the specified ports (REST) without the prefix and this works internally.
version: "3"
services:
   reverse-proxy:
     image: traefik:v2.9
     command:
       - "--log.level=DEBUG"
       - "--api.insecure=true"
       - "--providers.docker=true"
       - "--providers.docker.exposedByDefault=true"
       - "--entrypoints.web.address=:80"
       - "--accesslog=true"
     ports:
       - "80:80"
       - "8080:8080"
     volumes:
       - /var/run/docker.sock:/var/run/docker.sock

   u10:
     image: "u10"
#     container_name: u10     
#     ports:
#       - 8540:8540                           # !!!
     depends_on:
       - messagebus
     restart: always
     networks:
      - attestationnetwork
     volumes:
      - ./a10.conf:/etc/a10.conf      # !!!
     labels:
       - "traefik.enable=true"
 #      - "traefik.port=8540"
       - "traefik.docker.network=my-internal-network"
       - "traefik.http.routers.u10.rule=PathPrefix(`/u10`)"
       - "traefik.http.routers.u10.entrypoints=web"
       - "traefik.http.routers.u10.middlewares=u10"
       - "traefik.http.middlewares.u10.stripprefix.prefixes=/u10" 
       - "traefik.http.middlewares.u10.stripprefix.forceSlash=false"
       - "traefik.http.routers.u10.service=u10"       
       - "traefik.http.services.u10.loadbalancer.server.port=8540"

networks:
   my-internal-network:
     driver: bridge

**Tags:** docker, docker-compose, networking, traefik


---

## 1 answers

### Answer by username_1 on 2022-11-29. Score: 0

I can't tell exactly what you are trying, it looks like you might just not have Traefik and the services on the same network.
Its also helpful to have a domain that's going to resolve to 127.0.0.1 on wildcard queries.
This might be a valuable starting point as a working example.
networks:
  traefik:
    name: demo_traefik

services:

  proxy:
    image: traefik:latest
    command: >
      --accesslog=true
      --api.insecure=true
      --log.level=DEBUG
      --providers.docker=true
      --providers.docker.network=demo_traefik
    ports:
    - "80:80"
    - "8080:8080"
    networks:
    - traefik
    volumes:
    - /var/run/docker.sock:/var/run/docker.sock
    labels:
      traefik.http.routers.demo_traefik.rule: Host(`traefik.localtest.me`)
      traefik.http.services.demo_traefik.loadbalancer.server.port: 8080

  example:
    image: nginx
    networks:
    - traefik
    scale: 4
    labels:
      traefik.http.routers.demo_nginx.rule: Host(`example.localtest.me`)
      traefik.http.services.demo_nginx.loadbalancer.server.port: 80

  whoami:
    image: traefik/whoami
    networks:
    - traefik
    labels:
      traefik.http.middlewares.whoami_strip.stripprefix.prefixes: /whoami
      traefik.http.routers.whoami.rule: Host(`example.localtest.me`) && PathPrefix(`/whoami`)
      traefik.http.routers.whoami.middlewares: whoami_strip

docker compose up and then visit http://example.localtest.me/whoami in your browser.


---

