tmate / Dockerfile
xdragxt's picture
Update Dockerfile
edf25b0 verified
raw
history blame
1.03 kB
FROM python:3.10
# Create a non-root user
RUN useradd -m -u 1000 user
ENV PATH="/home/user/.local/bin:$PATH"
# Set working directory
WORKDIR /app
# Install dependencies
COPY requirements.txt requirements.txt
RUN pip install --no-cache-dir --upgrade -r requirements.txt
# Install tmate and required tools
RUN apt-get update && apt-get install -y curl git tmate && apt-get clean
# Copy app code
COPY . /app
# Set permissions for non-root user
RUN chown -R user:user /app
# Create startup script that logs tmate link
RUN cat << 'EOF' > /app/start.sh
#!/bin/bash
# Start tmate in the background and write output to log
tmate -F > /tmp/tmate.log 2>&1 &
# Wait for tmate to initialize
sleep 2
# Print the SSH/web link from the tmate log
grep -E "ssh|web|https" /tmp/tmate.log || tail -n 20 /tmp/tmate.log
# Start FastAPI app
exec uvicorn main:app --host 0.0.0.0 --port 7860
EOF
# Make the script executable
RUN chmod +x /app/start.sh
# Switch to non-root user
USER user
# Run the startup script
CMD ["bash", "/app/start.sh"]