Start here. This is the direct spoken answer to practice first.
Why this question matters
Docker reuses an instruction only when that layer and its inputs still match. The order of COPY and restore steps determines whether an ordinary source edit invalidates the expensive dependency layer.
I would keep the build context small with .dockerignore, then copy solution, project, and dependency files before running dotnet restore. Source files are copied afterward, so a code-only change can reuse the restore layer. I would include every file that affects restore, such as NuGet.config, Directory.Build.props, Directory.Packages.props, and lock files, so the cache is fast without becoming stale.