dongre8505 2019-06-20 07:03
浏览 198

在docker的上游找不到Docker + Nginx主机

I'm trying to run Nginx and PHP-FPM containers with network_mode: host in docker-compose, when defining a network_mode as "bridge" it works fine, but when defining network_mode as "host" I receive :

nginx: [emerg] host not found in upstream "ui" in /etc/nginx/conf.d/ui.conf:10

Everything works fine when setting network_mode to bridge, unfortunately I need to set it to host, as I need access to host network so I can access ueye camera.

This is my docker-compose file

version: '3'

services:
 nginx:
    image: nginx:alpine
    container_name: nginx
    tty: true
    ports:
      - "80:80"
      - "443:443"
      - "8000:8000"
    volumes:
      - ./../../ui/:/var/www/
      - ./nginx/:/etc/nginx/conf.d/
    network_mode: host

    depends_on:
      - ui
    restart: always
 ui:
    build:
      context: ./../../ui
      dockerfile: Dockerfile
    volumes:
      - ./../../ui/:/var/www/
    container_name: ui
    tty: true
    environment:
      SERVICE_NAME: ui
    working_dir: /var/www
    network_mode: host
    ports:
      - "9000:9000"

The nginx conf file

server {
    listen 80;
    index index.php index.html;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /var/www/public;
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass ui:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
    location / {
        try_files $uri $uri/ /index.php?$query_string;
        gzip_static on;
    }
}
  • 写回答

1条回答 默认 最新

  • dongtuo2373 2019-06-20 07:42
    关注

    While using host network mode, your container will see Docker host as localhost & not the container itself because it's using the host network. Try replacing ui with localhost in your nginx conf -

        fastcgi_pass localhost:9000;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿