1
Fork 0
crypto_bot_training/trading_bot/Dockerfile
2025-07-15 08:18:00 +07:00

73 lines
No EOL
1.8 KiB
Docker

# Trading Bot Dockerfile
# Multi-stage build for optimized production image
FROM python:3.11-slim as builder
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV PIP_NO_CACHE_DIR=1
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
curl \
git \
&& rm -rf /var/lib/apt/lists/*
# Create and set working directory
WORKDIR /app
# Copy requirements and install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY . .
# Production stage
FROM python:3.11-slim as production
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV PYTHONPATH=/app
# Install minimal runtime dependencies
RUN apt-get update && apt-get install -y \
curl \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user for security
RUN groupadd -r tradingbot && useradd -r -g tradingbot tradingbot
# Create application directory
WORKDIR /app
# Copy Python packages from builder stage
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
# Copy application code
COPY --chown=tradingbot:tradingbot . .
# Create necessary directories
RUN mkdir -p /app/logs /app/data && \
chown -R tradingbot:tradingbot /app/logs /app/data
# Create volume mount points
VOLUME ["/app/logs", "/app/data"]
# Switch to non-root user
USER tradingbot
# Expose port (if needed for monitoring)
EXPOSE 8000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD python -c "import requests; requests.get('http://localhost:8000/health')" || exit 1
# Default command
CMD ["python", "main.py"]