docs icon indicating copy to clipboard operation
docs copied to clipboard

Update django.md

Open mic-max opened this issue 3 years ago • 1 comments

I believe this is the reason but was only guessing as I went through this example. Please let me know if this is an inaccurate statement and I can update with a better explanation.

Proposed changes

Add explanation for why requirements.txt is copied and installed before copying the entire directory over. Does this effectively COPY the requirements.txt into the destination twice? Or will Docker or the operating system detect that it's the same file. I don't see anywhere in the COPY documentation anything explicitly saying it will overwrite existing files either.

mic-max avatar May 16 '22 19:05 mic-max

Deploy Preview for docsdocker ready!

Name Link
Latest commit 73d609d8cc154f1d84387336aecb0a62bdb27ead
Latest deploy log https://app.netlify.com/sites/docsdocker/deploys/62829f6b3bdf780009e91523
Deploy Preview https://deploy-preview-14752--docsdocker.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

netlify[bot] avatar May 16 '22 19:05 netlify[bot]

Thanks @mic-max for your contribution. The idea of the two COPY instructions is to have a fast inner loop cycle when you develop the application. The COPY . /code/ instruction is probably very fast, so there is no advantage to fail fast.

The time consuming step is the pip install to download and install tall dependencies. When you develop an application it is more likely that you change code and not always the requirements.txt file. When you rebuild the image layer caching can speed up the build time to just skip the pip install when the requirements.txt file hasn't changed. The docker build then only has to copy the sources again to build the new image.

Answering your question, yes the requirements.txt file will be copied twice with the two COPY instructions, but this is typically only a very small file, so there's no need to make the second COPY line more unreadable to optimise this, the COPY . /code/ is still a good practise.

Do you want to rephrase your PR to highlight the layer caching instead of the fail fast?

StefanScherer avatar Oct 25 '22 08:10 StefanScherer

Thanks @mic-max for your contribution. The idea of the two COPY instructions is to have a fast inner loop cycle when you develop the application. The COPY . /code/ instruction is probably very fast, so there is no advantage to fail fast.

The time consuming step is the pip install to download and install tall dependencies. When you develop an application it is more likely that you change code and not always the requirements.txt file. When you rebuild the image layer caching can speed up the build time to just skip the pip install when the requirements.txt file hasn't changed. The docker build then only has to copy the sources again to build the new image.

Answering your question, yes the requirements.txt file will be copied twice with the two COPY instructions, but this is typically only a very small file, so there's no need to make the second COPY line more unreadable to optimise this, the COPY . /code/ is still a good practise.

Do you want to rephrase your PR to highlight the layer caching instead of the fail fast?

Thanks for the explanation, that makes sense requirements.txt should be quite small :)

mic-max avatar Oct 25 '22 21:10 mic-max