Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Dockerfile best practices to speed up builds #243

Closed
wants to merge 2 commits into from

Conversation

aidansteele
Copy link
Contributor

@aidansteele aidansteele commented Aug 4, 2016

I noticed that there was some room for improvement in the Dockerfiles created by the Yeomen generator. There are two parts to it:

  • Run the apt-get commands before any project-specific commands.
  • Copy only project.json before running dotnet restore, then copy the rest before dotnet 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.json changes.

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.

@dnfclas
Copy link

dnfclas commented Aug 4, 2016

Hi @aidansteele, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution!

In order for us to evaluate and accept your PR, we ask that you sign a contribution license agreement. It's all electronic and will take just minutes. I promise there's no faxing. https://cla2.dotnetfoundation.org.

TTYL, DNFBOT;

@dnfclas
Copy link

dnfclas commented Aug 4, 2016

@aidansteele, Thanks for signing the contribution license agreement so quickly! Actual humans will now validate the agreement and then evaluate the PR.

Thanks, DNFBOT;

@SteveSandersonMS
Copy link
Member

Thanks for this! It's now merged. I am a novice with Docker so I definitely appreciate your suggestion about this.

I would have also added a .dockerignore to the templates

If you can show me what you think the resulting .dockerignore files should contain (e.g., just post that into a new issue), I can update the generator code to emit them.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants