chatbot_final / Dockerfile
Krish-05's picture
added voice
9f7a5a6 unverified
FROM python:3.9-slim
# Install curl, Node.js, Ollama, and Nginx in a single RUN instruction
RUN apt-get update && \
apt-get install -y curl nginx && \
# Install Ollama (using their official script)
curl -fsSL https://ollama.ai/install.sh | sh && \
# Install Node.js 18.x from NodeSource
curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
apt-get install -y nodejs && \
# Clean up APT caches to reduce image size
apt-get clean && rm -rf /var/lib/apt/lists/*
# Create Nginx cache/temp and log directories as root
RUN mkdir -p /var/cache/nginx /var/lib/nginx/body /var/lib/nginx/fastcgi /var/lib/nginx/proxy /var/lib/nginx/scgi /var/lib/nginx/uwsgi /var/log/nginx
# Set up user and environment
# Running as a non-root user is good practice
RUN useradd -m -u 1000 user
# NOW chown the directories, after the user 'user' is created
RUN chown -R user:user /var/cache/nginx /var/lib/nginx /var/log/nginx && \
chmod -R 755 /var/cache/nginx /var/lib/nginx /var/log/nginx
# --- CRITICAL CHANGE: Move USER instruction HERE ---
USER user
ENV HOME=/home/user \
PATH="/home/user/.local/bin:$PATH"
WORKDIR $HOME/app
# Copy requirements.txt FIRST to leverage Docker caching for Python dependencies
COPY --chown=user requirements.txt .
RUN pip install --no-cache-dir --upgrade -r requirements.txt
# Copy the entire frontend directory early to ensure Node.js dependencies are installed
COPY --chown=user frontend frontend/
# Install Node.js dependencies for the frontend and build it
RUN cd frontend && npm install --production=false && npm run build
# Copy the Nginx configuration
COPY --chown=user nginx.conf /etc/nginx/nginx.conf
# Copy the rest of the application files AFTER dependencies are installed
COPY --chown=user . .
# Make the start script executable
RUN chmod +x start.sh
# Expose ports for FastAPI (7860) and Nginx (8501)
EXPOSE 7860
EXPOSE 8501
# Command to execute when the container starts
CMD ["./start.sh"]