Dockerfile 804 B

1234567891011121314151617181920212223242526272829303132
  1. FROM python:3.9.2-alpine
  2. # upgrade pip
  3. RUN pip install --upgrade pip
  4. # get curl for healthchecks
  5. RUN apk add curl
  6. # permissions and nonroot user for tightened security
  7. RUN adduser -D nonroot
  8. RUN mkdir /home/app/ && chown -R nonroot:nonroot /home/app
  9. RUN mkdir -p /var/log/flask-app && touch /var/log/flask-app/flask-app.err.log && touch /var/log/flask-app/flask-app.out.log
  10. RUN chown -R nonroot:nonroot /var/log/flask-app
  11. WORKDIR /home/app
  12. USER nonroot
  13. # copy all the files to the container
  14. COPY --chown=nonroot:nonroot . .
  15. # venv
  16. ENV VIRTUAL_ENV=/home/app/venv
  17. # python setup
  18. RUN python -m venv $VIRTUAL_ENV
  19. ENV PATH="$VIRTUAL_ENV/bin:$PATH"
  20. RUN export FLASK_APP=app.py
  21. RUN pip install -r requirements.txt
  22. # define the port number the container should expose
  23. EXPOSE 5000
  24. CMD ["python", "app.py"]