FROM alpine:latest # Install Tor, Python, and dependencies RUN apk update && \ apk add tor python3 py3-pip curl --update-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing/ && \ rm -rf /var/cache/apk/* # Create app directory WORKDIR /app # Copy requirements file COPY requirements.txt /app/requirements.txt # Create and activate virtual environment, then install dependencies RUN python3 -m venv /app/venv && \ /app/venv/bin/pip install --no-cache-dir -r /app/requirements.txt # Copy application files COPY app.py /app/app.py COPY torrc /etc/tor/torrc COPY start.sh /app/start.sh # Ensure tor user and group exist, set permissions RUN if ! getent group tor >/dev/null; then addgroup -S tor; fi && \ if ! getent passwd tor >/dev/null; then adduser -S -G tor tor; fi && \ mkdir -p /var/lib/tor && \ chown -R tor:tor /etc/tor /var/lib/tor && \ chmod +x /app/start.sh # Expose Flask and SOCKS5 ports EXPOSE 5000 9050 # Run start script CMD ["/app/start.sh"]