

The model is served via FastAPI and is already using the best practices like uvicorn there. While I have seen this approach in the wild, most of the ones I have seen were already using the basic things I will improve in the first sections.Īs an example, I have built a really simple machine learning model using scikit-learn and LightGBM that predicts a fare price for a taxi trip in New York City.

I have chosen a particularly bad one here to explain some more things. There are several simple but not so effective approaches to put conda environments into a container. We will look at all the flaws this approach brings with it and optimise the workflow bit-for-bit until we reach a near-perfect container. In this article, I though want to start at the beginning again and have a look at the most obvious way one would put a conda environment into a Docker container. Over the course of time, we have also developed new techniques that help trim down the sizes of Docker containers even further. Due to changes in the default content of conda-forge packages and specific optimisation of some particular heavy packages, it will though yield fewer savings nowadays. It is still as valid nowadays as it was back then. But with a bit more love for details, you can optimise the process so that the build is faster and the resulting container much smaller.įor optimising conda-environments-in-docker Jim Crist-Harif’s “Smaller Docker images with Conda” blog post has been the go-to resource for a long time.

A better flow will depend on your need.Deploying conda environments in (Docker) containers - how to do it rightĭeploying conda environments inside a container looks like a straight-forward conda install. This will install on activated envĪt the end of the day, conda is there to help you. Python -m pip install -r requirements.txtĪt any point, we can add packages in conda environment with # this will install requests to ml_api env. I will do: conda create -name ml_api python=3.7 -c conda-forge scikit-learn pandas

For example, if I have a project with requirements.txt to be installed with pip but would like it to have pandas and scikit-learn from conda-forge. In fact, we often use a mix here and there.
