-
-
Notifications
You must be signed in to change notification settings - Fork 659
Expand file tree
/
Copy pathDockerfile
More file actions
65 lines (49 loc) · 1.57 KB
/
Dockerfile
File metadata and controls
65 lines (49 loc) · 1.57 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Multi-stage Dockerfile for TorBot
# Stage 1: Build stage
FROM python:3.11.4 as builder
# Set working directory
WORKDIR /build
# Install system dependencies required for building Python packages
RUN apt-get update && apt-get install -y \
gcc \
g++ \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements first for better layer caching
COPY requirements.txt .
# Create virtual environment and install dependencies
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt
# Stage 2: Runtime stage
FROM python:3.11.4-slim as runtime
# Create non-root user for security
RUN groupadd -r torbot && useradd -r -g torbot torbot
# Install runtime dependencies only
RUN apt-get update && apt-get install -y \
curl \
&& rm -rf /var/lib/apt/lists/*
# Copy virtual environment from builder stage
COPY --from=builder /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Set working directory
WORKDIR /app
# Copy application code
COPY --chown=torbot:torbot . /app
# Set environment variables
ENV PYTHONPATH="/app"
ENV SOCKS5_PORT=9050
ENV PYTHONUNBUFFERED=1
# Switch to non-root user
USER torbot
# Expose port
EXPOSE $SOCKS5_PORT
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD python -c "import sys; sys.exit(0)"
# Default command
CMD ["python", "torbot.py", "--help"]
# Labels for better image management
LABEL maintainer="TorBot Team"
LABEL version="4.2.0"
LABEL description="TorBot - A web scraping and analysis tool with Tor support"