I implemented a wordle game based on Flask and MySQL: https://github.com/Goer17/wordle-flask
When I run my program with Docker, the console shows that:
web-1 | * Serving Flask app 'app.py'
web-1 | * Debug mode: off
web-1 | WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
web-1 | * Running on http://127.0.0.1:5000
But I find it that I can't open the link as my browser trigger a 403 error.
The following are my docker-compose.yaml and Dockerfile:
version: '3.8'
services:
web:
build: .
ports:
- "5001:5000"
depends_on:
- db
environment:
FLASK_APP: app.py
FLASK_ENV: development
db:
image: mysql:innovation-oracle
environment:
MYSQL_DATABASE: wordle
# MYSQL_USER: user
# MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password
ports:
- "3306:3306"
FROM python:3.8-slim
WORKDIR /app
COPY . /app
RUN apt-get update && apt-get install -y netcat-traditional && rm -rf /var/lib/apt/lists/*
RUN pip install --no-cache-dir -r requirements.txt
RUN flask db init
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENV FLASK_APP=app.py
EXPOSE 5000
ENTRYPOINT ["/entrypoint.sh"]
You can see more information in my repo.
I attempted to run my program directly without using Docker, and it successfully executed.
Assuming that your project looks something like this:
The
requirements.txtmust specifyFlask.Dockerfile(I have commented outflask db initbecause I don't know what you have implemented there.)docker-compose.ymlentrypoint.shapp.y(A test application.)In your Docker Compose configuration you are mapping port 5000 on the container to port 5001 on the host. So to connect to the app you need to browse to http://127.0.0.1:5001.