We deploy Python app via uwsgi, so we have 2 directions:
- build python runtime in a separated service (base on Docker python and then install requirements.txt via all via docker-compose) and then uwsgi point to this python
pyruntime: image: bkinno/uwsgi:latest working_dir: /src volumes: - .:/src environment: PYTHONUSERBASE: /src/.pyenv command: pip install -r requirements.txt --user --upgrade
- build an image which contains uwsgi + python runtime
myapp-back: image: myapp-back build: context: . dockerfile: ./Dockerfile.back volumes: - ./back:/src - ./myapp-back.uwsgi.ini:/uwsgi/myapp-back.uwsgi.ini working_dir: /src ports: - '5000:5000' networks: - backend depends_on: - database environment: PYTHONPATH: /src PYTHONUSERBASE: /src/.pyenv command: uwsgi --ini /uwsgi/myapp-back.uwsgi.ini
In fact, the first approche, we do not need to build the image, just run the container and it will install requirements in persistent place, and then uwsgi will point to it. So it faster than second approche.
In the second method, if we want to update the runtime, we have to rebuild the image and this take too much time (we tested it and found that).
So for being more efficient, we decide to use the first one