Jenkins Docker容器背后traefik反向代理与路径匹配规则

时间:2017-12-15 18:14:21

标签: docker jenkins traefik

我有一个运行traefik reverse proxy的Docker容器,如下所示:

docker run \
  -d \
  --name traefik-reverse-proxy \
  --network="host" \
  -p 80:80 \
  -v /dev/null:/etc/traefik/traefik.toml \
  -v /var/run/docker.sock:/var/run/docker.sock \
  traefik:1.5-alpine \
    --docker

然后我使用Jenkins运行另一个容器,它通过标签配置转发规则,以便traefik将所有请求转发给路径以/jenkins开头的所有请求:

docker run \
  -d \
  --name jenkins \
  --label "traefik.port=8080" \
  --label "traefik.frontend.rule=PathPrefix: /jenkins" \
  jenkins/jenkins:lts

现在,打开http://localhost/jenkins,请求被正确转发到Jenkins容器,该容器将我重定向到主index.html页面。但是,该页面大部分都是空白的,因为JavaScript和CSS资产未正确加载。

查看浏览器控制台,我可以看到索引页面正在尝试从http://localhost/static/4e9c623d/scripts/yui/button/button-min.js这样的地址加载它们,这些地址在此设置中不存在。相反,它应该在网址中包含/jenkins/部分并尝试从例如http://localhost/jenkins/static/4e9c623d/scripts/yui/button/button-min.js而是 - 手动点击该URL会在浏览器中显示JS文件。

我尝试使用像--label "traefik.frontend.rule=PathPrefix: /jenkins; AddPrefix: /jenkins/"这样的规则组合,但这并没有改变任何内容。

我如何编写规则以使其正常工作?

1 个答案:

答案 0 :(得分:4)

您需要将自定义路径添加到环境变量,例如运行Jenkins容器时Sub BrokerCheckSlim() Dim IE As New InternetExplorer, html As HTMLDocument Dim post As Object, elem As Object With IE .Visible = True .navigate "https://brokercheck.finra.org/" Do Until .readyState = READYSTATE_COMPLETE: Loop Set html = .document End With For Each post In html.getElementsByTagName("input") If InStr(post.placeholder, "Name or CRD#") > 0 Then post.Focus post.innerText = "martin": Exit For End If Next post For Each elem In html.getElementsByTagName("button") If InStr(elem.Type, "submit") > 0 Then elem.Click Next elem IE.Quit End Sub

请参阅https://github.com/jenkinsci/docker/blob/master/README.md#configuring-reverse-proxy