简体   繁体   中英

How to use Traefik proxy to redirect to different apps in docker

I have two apps in docker:

  • App A -> port 3001
  • App B -> port 3002

Now I have domain.com.

I want to redirect:

  • appa.domain.com to App A
  • appb.domain.com to App B

I tried to read the documentation and tried but had no success. The container for App A and B are running. The Traefik says to use docker compose as one way but I just want to keep the old container. Do I directly run the Traefik ./traefik --configFile=traefik.toml which is one of the way with config file.

I am not sure what to add to the config.

If you would like to go ahead with Nginx, I'll suggest you go ahead with jwilder's Nginx Reverse Proxy which will help you do the same thing with Nginx instead of Traefik.

All you need to do is simply run the Nginx reverse proxy container once. After that whenever you spin, say App A all you'll need to do is pass an extra variable in the command like docker run -e VIRTUAL_HOST=appa.domain.com ... for every container

Have you checked the documentation of Traefik's docker backend?

You can configure the URL at which you expose the apps via a label on the container itself. For instance if you are using docker-compose, you can add something like this:

    labels:
      traefik.frontend.rule: Host:appa.domain.com
      traefik.enable: "true" 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM