# Use a base image with Python FROM python:3.9 # Install MySQL RUN apt-get update && apt-get install -y mysql-server && apt-get clean # Set the working directory WORKDIR /app # Copy the current directory contents into the container at /app COPY . /app # Install any needed packages specified in requirements.txt RUN pip install --no-cache-dir -r requirements.txt # Set environment variables for MySQL ENV MYSQL_ROOT_PASSWORD=rootpassword ENV MYSQL_DATABASE=mydatabase ENV MYSQL_USER=myuser ENV MYSQL_PASSWORD=mypassword # Expose port 80 for the FastAPI app and 3306 for MySQL EXPOSE 7860 3306 # Initialize MySQL and run FastAPI CMD service mysql start && mysql -e "CREATE DATABASE IF NOT EXISTS ${MYSQL_DATABASE}; GRANT ALL ON ${MYSQL_DATABASE}.* TO '${MYSQL_USER}'@'localhost' IDENTIFIED BY '${MYSQL_PASSWORD}'; FLUSH PRIVILEGES;" && uvicorn main:app --host 0.0.0.0 --port 7860