File size: 1,636 Bytes
d2ac649
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Use the official Alpine image as the base
FROM docker.io/library/alpine:latest@sha256:8a1f59ffb675680d47db6337b49d22281a139e9d709335b492be023728e11715

# Switch to root user to install dependencies
USER root

# Install Tor, Nyx, Python, and pip
RUN apk update && apk upgrade && \
    apk add tor nyx python3 py3-pip && \
    rm -rf /var/cache/apk/*

# Create a virtual environment and install Python dependencies
RUN python3 -m venv /venv
ENV PATH="/venv/bin:$PATH"
RUN pip install --no-cache-dir fastapi uvicorn requests pysocks

# Create Tor data directory and set permissions
RUN mkdir -p /var/lib/tor && \
    chown 1000:1000 /var/lib/tor && \
    chmod 700 /var/lib/tor

# Configure torrc
RUN echo "SocksPort 0.0.0.0:9050" >> /etc/tor/torrc && \
    echo "ControlPort 9051" >> /etc/tor/torrc && \
    echo "CookieAuthentication 1" >> /etc/tor/torrc && \
    echo "Log notice stdout" >> /etc/tor/torrc && \
    echo "DataDirectory /var/lib/tor" >> /etc/tor/torrc

# Set permissions for torrc
RUN chmod 644 /etc/tor/torrc && chown 1000:1000 /etc/tor/torrc

# Create app directory and copy the FastAPI app
RUN mkdir -p /app
COPY app.py /app/app.py

# Verify app.py exists, is readable, and contains the expected content
RUN ls -la /app && \
    cat /app/app.py && \
    chmod 644 /app/app.py && \
    chown 1000:1000 /app/app.py

# Expose ports (9050 for Tor SOCKS, 7860 for FastAPI)
EXPOSE 9050 7860

# Switch to non-root user (Hugging Face runs as UID 1000)
USER 1000

# Start Tor in the background and run FastAPI
CMD sh -c "tor -f /etc/tor/torrc & sleep 10 && /venv/bin/uvicorn --app-dir /app app:app --host 0.0.0.0 --port 7860"