# Set the working directory WORKDIR /app # Copy the current directory contents into the container COPY . /app # Define the user ID ARG USER_ID=1000 ENV USER_ID=$USER_ID # Create a new user if it doesn't exist RUN if [ -z "$USER_ID" ]; then \ echo "User ID not provided. Using the default user ID 1000."; \ USER_ID=1000; \ fi && \ if id "$USER_ID" >/dev/null 2>&1; then \ echo "User with ID $USER_ID already exists."; \ else \ adduser --uid "$USER_ID" --disabled-password --gecos '' appuser; \ fi # Set permissions RUN chown -R appuser:appuser /app && chmod -R 755 /app # Install necessary tools RUN apt-get update && apt-get install -y gosu && rm -rf /var/lib/apt/lists/* # Set up the entrypoint script COPY entrypoint.sh /usr/local/bin/entrypoint.sh RUN chmod +x /usr/local/bin/entrypoint.sh # Switch to the non-root user USER appuser # Define the entrypoint ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] # Default command CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860", "--reload"]