Mapping to path in Docker container

I want to point via www.domain.ch to a path of the service in the docker container ('/service1'). I have already seen the redirect that /service1 then appears in the path, but actually I want traefik to do this mapping in the background. does anyone have a tip for me?
Thanks and greetings
André

Hello @nwc-ch,

For this, you need 2 things:
The first one is a service that can redirect requests to your docker container (with the IP of my-container) to the path /service1.

http:
  services:
    my-service:
      loadBalancer:
        servers:
        - url: "http://my-container/service1"

The second one is a router to handle incoming requests. This router has a rule that match all requests with a Host of www.domain.ch.

http:
  routers:
    my-router:
      rule: "Host(`www.domain.ch`)"
      service: my-service

Now, if you have a request that comes to traefik with a host of www.domain.ch, traefik will redirect it to http://my-container/service1.

PS, all of there is done using the file provider.

WDYT ?

1 Like

Hey
I want to apply this solution inside of the docker.compose.yml file. But every time when I go to domain adress I got 404. I added some file in the k8 path and tried to go to domain I got 404 again.
Does anyone have a tip for me? Thanks

NOTE: When you go to my_container_ıp:8500 address it directs you to the app folder which is inside of the container.

my docker.compose.yml file:

version: "3"

services:
  coldfusion:
    build: 
      context: .
      dockerfile: Dockerfile
    container_name: cf
    image: cf
  
    restart: unless-stopped

    security_opt:
      - no-new-privileges:true

    volumes:
      - ./jdk:/opt/coldfusion/jdk
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro

    ports:

      - 8500:8500
    
    environment:
      - acceptEULA=YES
      - password=123

    networks:
      - traefik-proxy

    labels:

      - "traefik.enable=true"
      - "traefik.http.routers.coldfusion.entrypoints=http"
      - "traefik.http.routers.coldfusion.rule=Host(`my.domain.com`)"
      - "traefik.http.routers.coldfusion.service=coldfusion"
      - "traefik.http.services.coldfusion.loadbalancer.server.port=8500"
      - "traefik.http.services.coldfusion.loadbalancer.server.url=http://my_container_ıp/k8"
      - "traefik.docker.network=traefik-proxy"
           


      
networks:
  traefik-proxy:
    external: true

my traefik.yml :

api:
  dashboard: true

entryPoints:
  http:
    address: ":80"
  https:
    address: ":443"

providers:
  docker:
    endpoint: "unix:///var/run/docker.sock"
    exposedByDefault: false

certificatesResolvers:
  http:
    acme:
      email: my-email
      storage: acme.json
      httpChallenge:
        entryPoint: http

Hello @ziyaacar,

I think your question is out of scope for this thread, but if you want a simple example on how to connect your docker services to traefik, I've made some example available here.

For example, I used a web server with a traefik reverse proxy.

Hope it helps :wink:

Hello,

First of all thanks for your answer. I've looked at the examples, but I guess I'd better explain what I mean;

I built an image from the coldfusion base image. An application server for my application. Coldfusion image has a built-in webserver called apache tomcat and its root directory inside the container is "/app" which means if you go to 127.0.0.1:8500 (the default port for coldfusion) in your browser you will see your web app. Here I need traefik.I want to point via my domain to a path of the service in the docker container ('/app/k8'). So I'm going to add my web app to this path ("app/k8") and I want traefik to do this mapping in the background.

And unlike your answer to the @nwc-ch, I dont want to use dynamic conf file. I want to do this configuration in docker.compose.yml via traefik labels

You set the router and service (targets) for Traefik in dynamic configuration. Dynamic configuration is read via providers in static config. Most used providers are Docker and File.

If your target is a Docker service/container, then you just need to set rule and port, Traefik will auto-discover the IP. (Simple Traefik example)

If you need to set manually an IP, then you need to use a separate file to declare router and service with loadbalancer.servers.url. You can’t do it in docker-compose.yml alone. (Docs)

But you can upvote this issue on Github, requesting support for this in labels :slight_smile:

So I am able to use both docker and file provider at the same time? Because I have already a docker.compose.yml with traefik labels as above and I dont wanna change that labels (for portainer and traefik services in my example)to dynamic.conf file. Is there a way to use the file provider for only one service( coldfusion service in my example)?

Yes, you can use multiple providers. And have one dynamic config file for one additional service.