我尝试在Heroku中部署带有PostgreSQL的React-Flask应用程序,但收到H10:应用程序崩溃错误。当在本地运行Docker映像时,我也收到一个错误消息,说localhost没有发送任何数据。Docker说它正在运行,但当转到localhost:8000或127. 0. 0. 1:8000时,它没有显示任何内容。我不知道这里出了什么问题。
停靠文件:
FROM node:12 AS build-stage
WORKDIR /react-app
COPY react-app/. .
# You have to set this because it should be set during build time.
ENV REACT_APP_BASE_URL=https://(blahblahblah).herokuapp.com/
# Build our React App
RUN npm install
RUN npm run build
FROM python:3.9
# Setup Flask environment
ENV FLASK_APP=app
ENV FLASK_ENV=production
ENV SQLALCHEMY_ECHO=True
EXPOSE 8000
WORKDIR /var/www
COPY . .
COPY --from=build-stage /react-app/build/* app/static/
# Install Python Dependencies
RUN pip install -r requirements.txt
RUN pip install psycopg2
# Run flask environment
CMD gunicorn app:app
停靠器命令:
docker build -f Dockerfile -t react-app .
docker run --env-file .env --rm -p 8000:8000 react-app
Docker构建输出:
(project_alpha) project_alpha % docker build -f Dockerfile -t react-app .
[+] Building 12.9s (17/17) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 639B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 105B 0.0s
=> [internal] load metadata for docker.io/library/python:3.9 0.7s
=> [internal] load metadata for docker.io/library/node:12 0.7s
=> [build-stage 1/5] FROM docker.io/library/node:12@sha256:01627afeb110b3054ba4a1405541ca095c8bfca1cb6f2be9479c767a2711879e 0.0s
=> [stage-1 1/6] FROM docker.io/library/python:3.9@sha256:cfcc9ef77b6cf87f57327aacc6f9b50c7cdb4d7dd93662a36549f05b7403cd47 0.0s
=> [internal] load build context 0.9s
=> => transferring context: 550.78kB 0.9s
=> CACHED [stage-1 2/6] WORKDIR /var/www 0.0s
=> [stage-1 3/6] COPY . . 0.3s
=> CACHED [build-stage 2/5] WORKDIR /react-app 0.0s
=> CACHED [build-stage 3/5] COPY react-app/. . 0.0s
=> CACHED [build-stage 4/5] RUN npm install 0.0s
=> CACHED [build-stage 5/5] RUN npm run build 0.0s
=> [stage-1 4/6] COPY --from=build-stage /react-app/build/* app/static/ 0.0s
=> [stage-1 5/6] RUN pip install -r requirements.txt 5.5s
=> [stage-1 6/6] RUN pip install psycopg2 5.0s
=> exporting to image 0.5s
=> => exporting layers 0.5s
=> => writing image sha256:acbaf8cfb553dfd8aa9f791eaea06f9f6bc31f6d9b6d77e7a0e771b78f46855b 0.0s
=> => naming to docker.io/library/react-app
Docker运行输出:
(project_alpha) project_alpha % docker run --env-file .env --rm -p 8000:8000 react-app
[2022-09-22 17:33:21 +0000] [7] [INFO] Starting gunicorn 20.1.0
[2022-09-22 17:33:21 +0000] [7] [INFO] Listening at: http://127.0.0.1:8000 (7)
[2022-09-22 17:33:21 +0000] [7] [INFO] Using worker: sync
[2022-09-22 17:33:21 +0000] [8] [INFO] Booting worker with pid: 8
1条答案
按热度按时间webghufk1#
这就是你的问题:
您的进程只监听本地接口。如果您打开容器中的一个shell并尝试 curl 该url,您将看到它工作。
您需要让您的应用程序改为侦听
0.0.0.0:8000
。