【问题标题】:Restrict jenkins only on localhost with docker and nginx使用 docker 和 nginx 仅在 localhost 上限制 jenkins
【发布时间】:2016-06-25 22:38:16
【问题描述】:

我有几个在 docker 容器(nginx、db、php、..)上运行的应用程序,它们与 docker-compose 连接在一起。现在我想使用 jenkins 在生产环境中构建这个应用程序。我不确定如何将 jenkins 容器与 nginx 连接并将其限制为 localhost。

nginx.conf

upstream jenkins {
        server jenkins:8080;
}

sites-enabled/default.conf

server {

    listen 80;

    server_name jenkins.example.com;

    location / {
      proxy_pass              http://jenkins;
      proxy_set_header        Host $host;
      proxy_set_header        X-Real-IP $remote_addr;
      proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header        X-Forwarded-Proto $scheme;
    }
}

詹金斯 Dockerfile

FROM jenkins

ENV JENKINS_OPTS --httpListenAddress=172.17.0.1

docker-compose.yml

jenkins:
  ports:
    - "8080:8080" 
nginx:
  links:
    - jenkins
  ports:
    - "80:80"
  ...

我收到 502 错误。当我将 --httpListenAddress 更改为 0.0.0.0 时,它可以工作,但不仅限于本地主机。 172.17.0.1 是 docker 网关。

【问题讨论】:

  • 0.0.0.0 通常表示监听所有接口。你试过 127.0.0.1 吗?
  • 是的,我试过没有成功。 Docker 监听 172.x.x.x

标签: nginx jenkins docker localhost


【解决方案1】:

从 jenkins 中删除端口条目。只需要将 docker 容器的端口公开给本地主机,就需要 ports 条目。

要将端口暴露给另一个 docker 容器,链接它们就足够了。在您的 nginx 链接中:您已经提到了 jenkins。因此,您不需要在 jenkins 中输入端口。

...
jenkins:
  ...
nginx:
  links:
    - jenkins
  ports:
    - "80:80"
  ...

【讨论】:

    【解决方案2】:

    试试看

    jenkins:
      ports:
        - "127.0.0.1:8080:8080" 
    nginx:
      links:
        - jenkins
      ports:
        - "80:80"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-20
      • 2016-12-28
      • 2015-05-25
      • 2019-12-11
      • 1970-01-01
      相关资源
      最近更新 更多