File size: 1,229 Bytes
25a173a 6c0ac6b 28e0451 9d69895 28e0451 fff159e 2185caa 7e9fa29 c57116e 9d69895 28e0451 200b2d8 28e0451 200b2d8 28e0451 2185caa |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
FROM python:3.10.9
# Create a non-root user and group with a specified UID and GID
RUN addgroup --gid 1001 appgroup && adduser --uid 1001 --gid 1001 --disabled-password --gecos "" appuser
# Create directories with appropriate permissions and change ownership
RUN mkdir -m 777 /tmp/NUMBA_CACHE_DIR /tmp/MPLCONFIGDIR /home/appuser/.local
RUN chown -R appuser:appgroup /tmp/NUMBA_CACHE_DIR /tmp/MPLCONFIGDIR /home/appuser/.local
# Set environment variables
ENV NUMBA_CACHE_DIR=/tmp/NUMBA_CACHE_DIR/
ENV MPLCONFIGDIR=/tmp/MPLCONFIGDIR/
ENV HOME=/home/appuser
ENV PATH="/opt/venv/bin:$PATH"
# Copy all files to the container
COPY . .
# Set the working directory
WORKDIR /
# Install virtualenv and set up the virtual environment as root
RUN python -m venv /opt/venv
# Change ownership of the virtual environment directory to the non-root user
RUN chown -R appuser:appgroup /opt/venv
# Switch to the non-root user
USER appuser
# Activate the virtual environment and install requirements
RUN /opt/venv/bin/pip install --no-cache-dir --upgrade pip && \
/opt/venv/bin/pip install --no-cache-dir --upgrade -r /requirements.txt
# Command to run the application
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|