nginx反向代理在docker-comopse中找不到后端服务

vmdwslir  于 4个月前  发布在  Nginx
关注(0)|答案(1)|浏览(61)

我有以下docker-compose.yaml

version: '3'

services:
  webapp:
    image: example/webapp
    build:
      context: app
    restart: always
    ports:
      - ":8181"
    deploy:
      replicas: 3
    volumes:
      - secret-store:/app/data
    env_file:
      - .env
    networks:
      - bridged_network

  nginx:
    image: example/reverseproxy
    build:
      context: reverseproxy
    ports:
      - "8181:80"
    depends_on:
      - webapp

networks:
  bridged_network:
    driver: bridge

volumes:
  secret-store:

字符串
nginx映像的构建过程如下

FROM nginx:latest

RUN rm /etc/nginx/conf.d/*
COPY nginx.conf /etc/nginx/conf.d/default.conf


其中nginx.conf

server {

  listen 80;

  location / {
    proxy_pass http://webapp:8181;
  }
}


但是在nginx容器日志中:

nginx: [emerg] host not found in upstream "webapp" in /etc/nginx/conf.d/default.conf:6


为什么nginx无法发现webapp服务?

hgtggwj0

hgtggwj01#

你的nginx反向代理和服务在同一个网络中吗?看起来它们不在同一个网络中。

相关问题