kyberorg
kyberorg

Reputation: 667

How to connect from nginx on docker host to application in container

The situation is: we have service with nginx, which also acts as docker server.

Also we have Java application in docker container, which listens at 8080.

The problem is permissions to connect from nginx to container's published port.

Nginx.error.log shows:

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

Site config is:

server {
listen 80 default_server;
server_name _;

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

Container config:

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

Permission happens because nginx user is nginx and docker user is root. How to fix this problem without moving nginx to container ? Or maybe there is some work around exists ?

Upvotes: 1

Views: 1211

Answers (1)

kyberorg
kyberorg

Reputation: 667

Problem was in SELinux configuration.

Solved by running:

setsebool -P httpd_can_network_connect 1

Upvotes: 1

Related Questions