Dockerfile best practices to speed up builds#243
Dockerfile best practices to speed up builds#243aidansteele wants to merge 2 commits intoaspnet:devfrom
Conversation
|
Hi @aidansteele, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution! TTYL, DNFBOT; |
|
@aidansteele, Thanks for signing the contribution license agreement so quickly! Actual humans will now validate the agreement and then evaluate the PR. |
|
Thanks for this! It's now merged. I am a novice with Docker so I definitely appreciate your suggestion about this.
If you can show me what you think the resulting |
I noticed that there was some room for improvement in the Dockerfiles created by the Yeomen generator. There are two parts to it:
apt-getcommands before any project-specific commands.project.jsonbefore runningdotnet restore, then copy the rest beforedotnet build.The rationale for both these changes is driven by how Docker caches intermediate images in building from a Dockerfile.
I won't duplicate that explanation here, but this means that Node.js won't need to be reinstalled on every code change and project dependencies won't need to be restored unless
project.jsonchanges.I hope you find this useful. I wouldn't have been able to get started down the ASP.Net SPA path without the generators, so keep up the great work.
EDIT: I would have also added a .dockerignore to the templates, but I'm not at all familiar with Yeomen generators and wasn't sure if it was as simple as dropping it in the right place. It's essentially the same syntax as the .gitignore. We don't want any build artifacts from the Docker host making their way into the Docker container.