Spaces:
Paused
Paused
| # Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker | |
| # you will also find guides on how best to write your Dockerfile | |
| FROM python:3 | |
| # Add new user 'user' (non-root) | |
| RUN useradd -m -u 1000 user | |
| # Set working dir to app | |
| ENV HOME=/home/user \ | |
| PATH=/home/user/.local/bin:$PATH | |
| RUN mkdir $HOME/app | |
| WORKDIR $HOME/app | |
| # Switch to root | |
| USER root | |
| # Install nginx and packages.txt | |
| RUN apt-get -y update && apt-get -y install nginx | |
| # Give app permissions to 'user' (non-root) | |
| RUN chown user:user . | |
| # Give nginx permissions to 'user' (non-root) | |
| # See https://www.rockyourcode.com/run-docker-nginx-as-non-root-user/ | |
| RUN mkdir -p /var/cache/nginx \ | |
| /var/log/nginx \ | |
| /var/lib/nginx | |
| RUN touch /var/run/nginx.pid | |
| RUN chown -R user:user /var/cache/nginx \ | |
| /var/log/nginx \ | |
| /var/lib/nginx \ | |
| /var/run/nginx.pid | |
| # Switch to 'user' (non-root) | |
| USER user | |
| # Install requirements.txt | |
| COPY --chown=user requirements.txt requirements.txt | |
| RUN pip install --no-cache-dir --upgrade -r requirements.txt | |
| # Copy nginx configuration | |
| COPY --chown=user nginx.conf /etc/nginx/sites-available/default | |
| # Copy app | |
| COPY --chown=user . . | |
| # Run | |
| CMD ["bash", "run.sh"] |