我尝试在docker-compose中使用network_mode: host运行Nginx和PHP容器,当将network_mode定义为“桥”时,它工作得很好,但是当将network_mode定义为“主机”时,我收到:
nginx:在/etc/nginx/conf.d/ui.conf:10的上游"ui“中找不到emerg主机
当设置network_mode为桥时,一切工作正常,不幸的是,我需要将其设置为主机,因为我需要访问主机网络,这样我才能访问ueye摄像头。
这是我的docker合成文件
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;
}
}发布于 2019-06-20 15:42:12
在使用主机网络模式时,您的容器将把Docker主机视为localhost &而不是容器本身,因为它正在使用主机网络。尝试在nginx conf中用localhost替换ui -
fastcgi_pass localhost:9000;https://stackoverflow.com/questions/56680667
复制相似问题