NoCodeTextClassifier / Dockerfile
Alamgirapi's picture
Update Dockerfile
4d55e84 verified
# Use Python 3.9 slim image
FROM python:3.9-slim
# Set working directory
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
curl \
software-properties-common \
git \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements and install Python dependencies
COPY requirements.txt ./
RUN pip3 install --no-cache-dir -r requirements.txt
# Set NLTK data directory to a location with proper permissions
ENV NLTK_DATA=/usr/local/share/nltk_data
RUN mkdir -p $NLTK_DATA
# Download NLTK data as root (with permissions) and handle SSL issues
RUN python -c "import ssl; ssl._create_default_https_context = ssl._create_unverified_context; import nltk; nltk.download('stopwords', download_dir='/usr/local/share/nltk_data'); nltk.download('wordnet', download_dir='/usr/local/share/nltk_data'); nltk.download('omw-1.4', download_dir='/usr/local/share/nltk_data')"
# Copy the application code
COPY . .
# Create necessary directories with proper permissions
RUN mkdir -p models artifacts vectorizers
RUN chmod -R 755 models artifacts vectorizers
# Create a non-root user for security
RUN useradd -m -u 1000 user
RUN chown -R user:user /app
USER user
# Set environment variables
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH \
PYTHONPATH=/app \
NLTK_DATA=/usr/local/share/nltk_data
# Expose the port that Streamlit runs on
EXPOSE 8501
# Run the application
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]