如何让traefik从docker内部重定向到特定的非docker端口 [英] How to get traefik to redirect to specific non-docker port from inside docker

查看:44
本文介绍了如何让traefik从docker内部重定向到特定的非docker端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,如果我没有使用正确的术语来问这个问题,我很抱歉,但我不适合现有的术语.

First of all I'm sorry if I'm not using the right terms to ask this question, but I'm not up to the terminology in place.

我在 docker 容器中运行 traefik 并使用 PathPrefix 选项提供一些服务,例如,www.myserver.com/wordpress 重定向到运行 wordpress 的 docker 容器.

I have traefik running in a docker container and serving some services with the PathPrefix option, for instance, www.myserver.com/wordpress redirects to a docker container running wordpress.

但是我如何让它重定向到 docker 容器之外呢?具体来说,我如何让 www.myserver.com 重定向到我机器中的端口 8080 以提供我在主机操作系统中运行的服务(而不是在 docker 容器中)?

But how do I get it to redirect to outside a docker container? Specifically, how do I get www.myserver.com to redirect to port 8080 in my machine to serve a service I have running there in the host OS (not in a docker container)?

这是我的traefik.toml:

logLevel = "DEBUG"
defaultEntryPoints = ["http", "https"]

[entryPoints]
    [entryPoints.http]
        address = ":80"
        compress = false
        [entryPoints.http.redirect]
            entryPoint = "https"
    [entryPoints.https]
        address = ":443"
        [entryPoints.https.tls]

[acme]
email = "mymail@mail.com"
storage = "acme.json"
entryPoint = "https"
onHostRule = true
#onDemand = true
[[acme.domains]]
    main = "www.myserver.com"

[web]
address = ":8888"

[docker]
endpoint = "unix:///var/run/docker.sock"
domain = "www.myserver.com"
watch = true
exposedbydefault = false

还有我的 docker-compose.yml 用于 traefik 容器:

And my docker-compose.yml for the traefik container:

version: "2"

services:
  traefik:
    image: traefik
    network_mode: "host"
    ports:
      - "80:80"
      - "443:443"
      - "8888:8888"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ${SERVER_DIR}/AppData/traefik:/etc/traefik/
      - ${PWD}/acme.json:/acme.json
      - ${PWD}/traefik.toml:/etc/traefik/traefik.toml
      - ${PWD}/servers.toml:/etc/traefik/servers.toml
    restart: never

推荐答案

我摸索着找到了答案.

traefik.toml 中添加:

################################################################
# File configuration backend
################################################################
# Enable file configuration backend
# Optional
[file]
        filename = "servers.toml"

# Enable watch file changes
        watch = true

docker-compose.yml 中将 volumes: 更改为:

In docker-compose.yml change the volumes: to:

volumes:
  - /var/run/docker.sock:/var/run/docker.sock
  - ${SERVER_DIR}/AppData/traefik:/etc/traefik/
  - ${PWD}/acme.json:/acme.json
  - ${PWD}/traefik.toml:/etc/traefik/traefik.toml
  - ${PWD}/servers.toml:/servers.toml

添加文件servers.toml:

loglevel = "ERROR"

[backends]
[backends.nasweb]
        [backends.nasweb.servers.nasweb]
            url = "http://192.168.1.11:8080"

[frontends]
        [frontends.domain]
                backend = "nasweb"
        [frontends.domain.routes.domain]
                rule = "Host:www.myserver.com"

这篇关于如何让traefik从docker内部重定向到特定的非docker端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆