# Builder stage | |
FROM python:3.10.0 as builder | |
# Create a non-root user | |
RUN useradd -ms /bin/bash admin | |
# Set the working directory | |
WORKDIR /srv | |
# Copy requirements file first to leverage caching | |
COPY --chown=admin requirements.txt . | |
# Install Python dependencies | |
RUN pip install --no-cache-dir -r requirements.txt | |
# Copy the application code | |
COPY --chown=admin . /srv | |
# Give read and write permissions to the admin user | |
RUN chown -R admin:admin /srv | |
RUN chmod 755 /srv | |
USER admin | |
CMD python -m uvicorn main:app --workers 1 --host 0.0.0.0 --port 7860 --log-level debug | |
# Expose port | |
EXPOSE 7860 |