Docker Compose Host Доступ к сети и обратный прокси - PullRequest
0 голосов
/ 01 ноября 2019

У меня есть ситуация, когда я создал микросервис, который может изменять сетевые настройки портов Ethernet Cat5 на работающем сервере. Для этого его необходимо установить в режим network_mode: host. Микросервис предоставляет HTTP-API rest rest, который я хотел бы иметь за обратным прокси-сервером nginx, но поскольку он использует мостовую сеть, я не могу получить доступ к сервису network_utilities (см. Файл docker-compose ниже). Любые предложения о том, как сделать эту работу?

Вот мой сжатый файл docker-compose:

version: '3.3'
services:
  nginx:
    image: nginx:stable
    container_name: production_nginx
    restart: unless-stopped
    ports:
      - 80:80
    depends_on:
      - smart-mobile-server
      - network_utilities
    volumes:
      - ./config/front-end-gui:/var/www/html
      - ./config/nginx:/etc/nginx
    networks:
      - smart-mobile-loopback
  smart-mobile-server:
    container_name: smart-mobile-rest-api
    image: smartmobile_server:latest
    build:
      context: .
      dockerfile: main.Dockerfile
    environment:
      NODE_ENV: production
    command: sh -c "pm2 start --env production && pm2 logs all"
    depends_on:
      - 'postgres'
    restart: unless-stopped
    networks:
      - smart-mobile-loopback
    volumes:
      - ~/server:/usr/app/dist/express-server/uploads
      - ~/server/logs:/usr/app/logs
  network_utilities:
    image: smartgear/network-utilities-service:latest
    network_mode: host
    environment:
      NODE_ENV: production
      REST_API_PORT: '64000'
    privileged: true

networks:
  smart-mobile-loopback:
    driver: bridge

nginx.conf

worker_processes  2;

events {
    # Connections per worker process
    worker_connections  1024;

    # Turning epolling on is a handy tuning mechanism to use more efficient connection handling models.
    use epoll;

    # We turn off accept_mutex for speed, because we don’t mind the wasted resources at low connection request counts.
    accept_mutex off;
}

http {

    upstream main_server {
        # least_conn Specifies that a group should use a load balancing method where a request is 
        #   passed to the server with the least number of active connections, 
        #   taking into account weights of servers. If there are several such 
        #   servers, they are tried in turn using a weighted round-robin balancing method.
        ip_hash;
        # These are references to our backend containers, facilitated by
        # Compose, as defined in docker-compose.yml   
        server smart-mobile-server:10010;
    }

    upstream network_utilities {
        least_conn;
        server 127.0.0.1:64000;
    }

    server {
        # GZIP SETTINGS FOR LARGE FILES
        gzip  on;
        gzip_http_version 1.0;
        gzip_comp_level 6;
        gzip_min_length 0;
        gzip_buffers 16 8k;
        gzip_proxied any;
        gzip_types text/plain text/css text/xml text/javascript application/xml application/xml+rss application/javascript application/json;
        gzip_disable "MSIE [1-6]\.";
        gzip_vary on;

        include /etc/nginx/mime.types;

        ## SECURITY SETTINGS
        # don't send the nginx version number in error pages and Server header
        server_tokens off;
        # when serving user-supplied content, include a X-Content-Type-Options: nosniff header along with the Content-Type: header,
        # to disable content-type sniffing on some browsers.
        add_header X-Content-Type-Options nosniff;


        listen 80;

        location / {
             # This would be the directory where your React app's static files are stored at
            root /var/www/html/;
            index index.html;

            try_files $uri /index.html;
        }

        location /api/documentation/network-utilities {
            proxy_pass http://network_utilities/api/documentation/network-utilities;
            proxy_set_header Host $host;
        }

        location /api/v1/network-utilities/ {
            proxy_pass http://network_utilities/;
            proxy_set_header Host $host;
        }

        location /api/ {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
            proxy_pass http://main_server/api/;
        }
    }

}


Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...