I am trying to deploy a React-Flask application with PostgreSQL in Heroku, but I am receiving a H10: App Crashed error. When running the Docker image locally, I also get an error saying localhost did not send any data. Docker says it is running, but it does not display anything when going to localhost:8000 or 127.0.0.1:8000. I am at a loss for what is going wrong here.
Dockerfile:
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 Commands:
docker build -f Dockerfile -t react-app .
docker run --env-file .env --rm -p 8000:8000 react-app
Docker Build Output:
(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 Run Output:
(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
Folder Structure: https://i.stack.imgur.com/YchWe.png
CodePudding user response:
This is your problem:
[2022-09-22 17:33:21 0000] [7] [INFO] Listening at: http://127.0.0.1:8000 (7)
Your process is only listening on the local interface. If you open a shell in the container and try to curl that url you will see it works.
You need to make your application listen on 0.0.0.0:8000
instead.