【问题标题】:How to connect from nginx on docker host to application in container如何从 docker 主机上的 nginx 连接到容器中的应用程序
【发布时间】:2017-11-23 11:56:20
【问题描述】:

情况是:我们有nginx的服务,它也充当docker服务器。

我们在 docker 容器中还有 Java 应用程序,它在 8080 处侦听。

问题是从 nginx 连接到容器的发布端口的权限。

Nginx.error.log 显示:

2017/11/23 13:44:12 [crit] 3599#0: *1 connect() to 127.0.0.1:8080 failed (13: Permission denied) while connecting to upstream,
2017/11/23 13:44:13 [error] 3599#0: *1 no live upstreams while connecting to upstream

网站配置是:

server {
listen 80 default_server;
server_name _;

location / {
   proxy_pass http://localhost:8080;
   include proxy.conf;
 }
}

容器配置:

version: '3'
services:
    app:
    image: user/appX
    restart: always
    container_name: appX
    ports:
     - "8080:8080"
    env_file:
      - ./appX.env
    extra_hosts:
      - "host:172.101.0.1"
    networks:
      mynet:
       ipv4_address: 172.101.0.2

 networks:
    mynet:
      external:
        name: mynet

权限发生是因为 nginx 用户是 nginx 而 docker 用户是 root。 如何在不将 nginx 移动到容器的情况下解决此问题? 或者也许有一些解决方法存在?

【问题讨论】:

  • docker ps 的输出是什么?
  • @ShawnC, 6d18f20bbb90 user/appX "/bin/sh -c 'exec ..." 21 小时前 Up 21 hours 0.0.0.0:8080->8080/tcp appX

标签: docker nginx networking docker-compose


【解决方案1】:

问题出在 SELinux 配置中。

通过运行解决:

setsebool -P httpd_can_network_connect 1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-16
    • 2018-01-31
    • 1970-01-01
    • 2016-11-19
    • 2017-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多