我正在尝试使用network_mode:docker-compose中的host运行Nginx和PHP-FPM容器,当将network_mode定义为“ bridge”时,它可以正常工作,但是当将network_mode定义为“ host”时,我会收到:
nginx:在/etc/nginx/conf.d/ui.conf:10的上游“ ui”中找不到[emerg]主机
将network_mode设置为网桥时,一切正常,不幸的是,我需要将其设置为主机,因为我需要访问主机网络才能访问ueye摄像机。
这是我的docker-compose文件
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"
nginx conf文件
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;
}
}
答案 0 :(得分:0)
在使用主机网络模式时,您的容器将Docker主机视为localhost而不是容器本身,因为它正在使用主机网络。尝试在您的nginx conf中将ui
替换为localhost
-
fastcgi_pass localhost:9000;