Thanks for the nice tutorial! I would like to mention to optimize the layer order in the build step a bit to actually benefit from the Docker cache: First, add the requirements.txt file and then immediately run the pip install command. Then add the entire source code with the RUN command or the ENTRYPOINT at the end. The advantage of this sequence is that changes in the source code (which tend to occur more frequently than changes in the requirements.txt) do not require the layers above to be rebuilt. In practice, this also works if you simply add the entire source code at the end, which could point to this advantage even more: --------------------------- FROM python:3-slim WORKDIR /app ADD requirements.txt ./ RUN pip install -r requirements.txt CMD ["python", "-u", "app.py"] ADD . ./ ---------------------------
Great video.
Thank you :)
Thanks for the nice tutorial!
I would like to mention to optimize the layer order in the build step a bit to actually benefit from the Docker cache:
First, add the requirements.txt file and then immediately run the pip install command. Then add the entire source code with the RUN command or the ENTRYPOINT at the end.
The advantage of this sequence is that changes in the source code (which tend to occur more frequently than changes in the requirements.txt) do not require the layers above to be rebuilt.
In practice, this also works if you simply add the entire source code at the end, which could point to this advantage even more:
---------------------------
FROM python:3-slim
WORKDIR /app
ADD requirements.txt ./
RUN pip install -r requirements.txt
CMD ["python", "-u", "app.py"]
ADD . ./
---------------------------
Really good addition! Thanks for that :)
I wanted to concentrate on building the image without much disturbance of other points to focus on.