| # Use the official Python base image | |
| FROM python:3.9-slim | |
| # Set the working directory in the container | |
| WORKDIR /app | |
| # Copy the requirements.txt file and install the Python dependencies | |
| COPY requirements.txt /app/ | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # Create a new user named "user" with user ID 1000 and set ownership | |
| RUN useradd -m -u 1000 user && chown -R user:user /app | |
| # Switch to the "user" user | |
| USER user | |
| # Set the working directory to the app folder | |
| WORKDIR /app | |
| # Copy the application code into the container | |
| COPY --chown=user:user . /app | |
| # Expose the port on which the Flask application will run | |
| EXPOSE 5000 | |
| # Set the environment variables for Flask | |
| ENV FLASK_APP=app.py | |
| # Run the Flask application | |
| CMD ["flask", "run", "--host=0.0.0.0"] | |