Docker 紧急情况1“1:在上游未找到主机”;仪表板fe:3000“;在/etc/nginx/nginx.conf:6中

Docker 紧急情况1“1:在上游未找到主机”;仪表板fe:3000“;在/etc/nginx/nginx.conf:6中,docker,nginx,docker-compose,Docker,Nginx,Docker Compose,我是docker的初学者,尝试将react和flask应用程序容器化。有三个容器,一个用于react,另一个用于flask,最后一个用于nginx负载平衡器。我使用docker compose运行所有容器。运行docker compose up命令时,我收到以下错误:- Creating dashboard_dashboard-be_1 ... done Creating dashboard_dashboard-fe_1 ... done Creating dashboard_nginx_1

我是
docker
的初学者,尝试将react和flask应用程序容器化。有三个容器,一个用于
react
,另一个用于
flask
,最后一个用于
nginx
负载平衡器。我使用
docker compose
运行所有容器。运行
docker compose up
命令时,我收到以下错误:-

Creating dashboard_dashboard-be_1 ... done
Creating dashboard_dashboard-fe_1 ... done
Creating dashboard_nginx_1        ... done
Attaching to dashboard_dashboard-fe_1, dashboard_dashboard-be_1, dashboard_nginx_1
dashboard-be_1  | [2021-03-10 17:44:38 +0000] [7] [INFO] Starting gunicorn 20.0.4
dashboard-be_1  | [2021-03-10 17:44:38 +0000] [7] [INFO] Listening at: http://0.0.0.0:5000 (7)
dashboard-be_1  | [2021-03-10 17:44:38 +0000] [7] [INFO] Using worker: threads
dashboard_dashboard-fe_1 exited with code 0
dashboard-be_1  | [2021-03-10 17:44:38 +0000] [10] [INFO] Booting worker with pid: 10
dashboard-be_1  | [2021-03-10 17:44:38 +0000] [11] [INFO] Booting worker with pid: 11
nginx_1         | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
nginx_1         | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
nginx_1         | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
nginx_1         | 10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
nginx_1         | 10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
nginx_1         | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
nginx_1         | /docker-entrypoint.sh: Configuration complete; ready for start up
nginx_1         | 2021/03/10 17:44:43 [emerg] 1#1: host not found in upstream "dashboard-fe:3000" in /etc/nginx/nginx.conf:6
nginx_1         | nginx: [emerg] host not found in upstream "dashboard-fe:3000" in /etc/nginx/nginx.conf:6

这似乎是一个相当常见的错误,在检查了许多答案后,我尝试用
dependens\u on
来修复它,但没有成功

以下是我的脚本:-

前端/Dockerfile

FROM node:10-alpine as build-step

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY package.json /usr/src/app/

RUN npm install

COPY . /usr/src/app
RUN npm run build
FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
nginx/Dockerfile

FROM node:10-alpine as build-step

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY package.json /usr/src/app/

RUN npm install

COPY . /usr/src/app
RUN npm run build
FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
docker compose.yml

version: '3'

services:
  dashboard-be:
    build: ./Dashboard-be
    expose:
      - 5000
    ports:
      - 5000:5000
    environment:
      - FLASK_ENV=${ENV}
      - FLASK_APP=app
      - PYTHONDONTWRITEBYTECODE=1
      - PYTHONUNBUFFERED=1
    networks:
      - dashboard_be

  dashboard-fe:
    build: ./Dashboard-fe
    expose:
      - 3000
    ports:
      - 3000:3000
    networks:
      - dashboard_fe

  nginx:
    build: ./nginx
    tty: true
    ports:
      - 80:80
    networks:
      - dashboard_fe
      - dashboard_be
    depends_on:
      - dashboard-fe
      - dashboard-be

networks:
  dashboard_fe:
  dashboard_be:
    internal: true

前端的
Dockerfile
中没有
CMD
,因此容器会启动然后退出,正如您在日志中看到的那样

dashboard_dashboard-fe_1 exited with code 0
一旦您更正了前端dockerfile并运行,整个撰写工作就应该开始了