# Use the official Python image as a base image FROM python:3.10-slim # Set environment variables ENV PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 # Add a non-root user RUN useradd -ms /bin/bash myuser # Install system dependencies RUN apt-get update && apt-get install -y \ sudo \ build-essential \ libpq-dev \ && rm -rf /var/lib/apt/lists/* # Grant sudo privileges to the non-root user RUN echo "myuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/myuser # Update the system RUN apt-get update && apt-get upgrade -y # Set the working directory in the container WORKDIR /app # Copy the requirements file and install dependencies COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Copy the Python script and .env file into the container COPY main.py . COPY .env . # Switch to the non-root user USER myuser # Run the Python script CMD ["python", "main.py"]