DEV Community

Discussion on: Getting Started with Flask and Docker 🐳🚀

Collapse
 
thebouv profile image
Anthony Bouvier

Nice article.

One point of optimization for your final Dockerfile example is to run the pip install piece after the requirements.txt is COPYed, instead of as far down as you put it.

Because of the layers, if requirements.txt doesn't change, the container will build faster by using the cache. But in your current set up, the second COPY command has a high likelihood of changing.

What you want to do is:

...
COPY ./requirements.txt /app/requirements.txt
RUN pip install -r /app/requirements.txt
COPY . /app
...
Enter fullscreen mode Exit fullscreen mode

Check out pythonspeed.com/articles/docker-ca... for more info.

Collapse
 
ken_mwaura1 profile image
Zoo Codes

Article updated. Thank you for the correction. Learnt something new