Skip to main content

ASP.NET Core Docker Build error - COPY failed: no source files were specified

Last week I had some time to play with the support for Docker in Visual Studio.

Creating the Docker enabled project

First thing I tried was creating a simple ASP.NET Core application with Docker enabled:

  • Open Visual Studio
  • Go to File –> New Project. Select the Web section and choose the ASP.NET Core Web Application template. Click OK.

image

  • On the next screen choose the Web Application template(or any other) and make sure that the Enable Docker Support checkbox is checked. Click OK to create the project.

image

  • 2 projects are created:
    • One Docker-Compose project that contains a yaml configuration to compose multiple containers
    • One web application project that contains a Dockerfile to compile and build your docker container.

Running the application in a docker container

  • Now that the application is created, it is time to build and run the application.
  • I opened a command prompt with the path set to the project containing my dockerfile and invoked the docker build command. Unfortunately this failed with the following error message:

C:\Projects\test\MyFirstContainer\WebApp1>docker build .

Sending build context to Docker daemon   4.73MB

Step 1/17 : FROM microsoft/aspnetcore:2.0 AS base

---> 9cd3adf8e0bd

Step 2/17 : WORKDIR /app

---> Using cache

---> 4a6bbedae1c7

Step 3/17 : EXPOSE 80

---> Using cache

---> 7a79975eb640

Step 4/17 : FROM microsoft/aspnetcore-build:2.0 AS build

---> e9127190cede

Step 5/17 : WORKDIR /src

Removing intermediate container 0926a125a0ca

---> bdfc28e52021

Step 6/17 : COPY *.sln ./

COPY failed: no source files were specified

       
  • This was not exactly what I expected. The way that Visual Studio sets up the docker file configuration is so that you are expected to use docker-compose build in the solution folder and not docker build in the specific project. So let’s try that:

C:\Projects\test\MyFirstContainer>docker-compose build
Building MyFirstContainer
Step 1/17 : FROM microsoft/aspnetcore:2.0 AS base
  ---> 9cd3adf8e0bd
Step 2/17 : WORKDIR /app
  ---> Using cache
  ---> 4a6bbedae1c7
Step 3/17 : EXPOSE 80
  ---> Using cache
  ---> 7a79975eb640
Step 4/17 : FROM microsoft/aspnetcore-build:2.0 AS build
  ---> e9127190cede
Step 5/17 : WORKDIR /src
Removing intermediate container c9c93c95e2ca
  ---> b9d9b88abe4a
Step 6/17 : COPY *.sln ./
  ---> 46f162cf683d
Step 7/17 : COPY MyFirstContainer/WebApp1.csproj MyFirstContainer/
  ---> 1180f56eecf1
Step 8/17 : RUN dotnet restore
  ---> Running in 36763ba9c396
/usr/share/dotnet/sdk/2.1.4/NuGet.targets(227,5): warning MSB3202: The project file "/src/docker-compose.dcproj" was not found. [/src/MyFirstContainer.sln]
/src/docker-compose.dcproj : warning NU1503: Skipping restore for project '/src/docker-compose.dcproj'. The project file may be invalid or missing targets required for restore. [/src/MyFirstContainer.sln]
  Restoring packages for /src/MyFirstContainer/WebApp1.csproj...
  Restoring packages for /src/MyFirstContainer/WebApp1.csproj...
  Restore completed in 2.46 sec for /src/MyFirstContainer/WebApp1.csproj.
  Installing Microsoft.DotNet.PlatformAbstractions 2.0.0.
  Installing Microsoft.Extensions.DependencyModel 2.0.0.
  Installing Microsoft.AspNetCore.Mvc.Core 2.0.0.
  Installing Microsoft.AspNetCore.Mvc.Razor.ViewCompilation 2.0.0.
  Installing Microsoft.AspNetCore.DataProtection.Extensions 2.0.0.
  Installing Microsoft.EntityFrameworkCore 2.0.0.
  Installing Microsoft.AspNetCore.Mvc.TagHelpers 2.0.0.
  Installing Microsoft.EntityFrameworkCore.Design 2.0.0.
  Installing Microsoft.Extensions.Identity.Core 2.0.0.
  Installing Microsoft.AspNetCore.Server.Kestrel.Core 2.0.0.
  Installing Microsoft.EntityFrameworkCore.SqlServer 2.0.0.
  Installing Microsoft.AspNetCore.Mvc.Razor 2.0.0.
  Installing Microsoft.VisualStudio.Web.BrowserLink 2.0.0.
  Installing Microsoft.Net.Http.Headers 2.0.0.
  Installing Microsoft.Extensions.Identity.Stores 2.0.0.
  Installing Microsoft.AspNetCore.HttpOverrides 2.0.0.
  Installing Microsoft.AspNetCore.Http 2.0.0.
  Installing Microsoft.EntityFrameworkCore.Sqlite.Core 2.0.0.
  Installing Microsoft.CodeAnalysis.Razor 2.0.0.
  Installing Microsoft.AspNetCore.Mvc.RazorPages 2.0.0.
  Installing Microsoft.AspNetCore.Mvc.Abstractions 2.0.0.
  Installing Microsoft.EntityFrameworkCore.InMemory 2.0.0.
  Installing Microsoft.AspNetCore.WebUtilities 2.0.0.
  Installing Microsoft.AspNetCore.StaticFiles 2.0.0.
  Installing Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv 2.0.0.
  Installing Microsoft.AspNetCore.Authentication.Facebook 2.0.0.
  Installing Microsoft.AspNetCore.WebSockets 2.0.0.
  Installing Microsoft.AspNetCore.Mvc.Razor.Extensions 2.0.0.
  Installing Microsoft.AspNetCore.DataProtection 2.0.0.
  Installing Microsoft.AspNetCore.NodeServices 2.0.0.
  Installing Microsoft.AspNetCore.Rewrite 2.0.0.
  Installing Microsoft.AspNetCore.ResponseCompression 2.0.0.
  Installing Microsoft.Extensions.Localization.Abstractions 2.0.0.
  Installing Microsoft.AspNetCore.Razor.Runtime 2.0.0.
  Installing Microsoft.AspNetCore.SpaServices 2.0.0.
  Installing Microsoft.AspNetCore.Session 2.0.0.
  Installing Microsoft.AspNetCore.Mvc.Formatters.Json 2.0.0.
  Installing Microsoft.AspNetCore.ResponseCaching 2.0.0.
  Installing Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore 2.0.0.
  Installing Microsoft.AspNetCore.Http.Abstractions 2.0.0.
  Installing Microsoft.AspNetCore.Mvc.Localization 2.0.0.
  Installing Microsoft.AspNetCore.Identity 2.0.0.
  Installing Microsoft.AspNetCore.Mvc.DataAnnotations 2.0.0.
  Installing Microsoft.AspNetCore.Mvc.Cors 2.0.0.
  Installing Microsoft.AspNetCore.Http.Extensions 2.0.0.
  Installing Microsoft.AspNetCore.Razor 2.0.0.
  Installing Microsoft.EntityFrameworkCore.Sqlite 2.0.0.
  Installing Microsoft.AspNetCore.ResponseCaching.Abstractions 2.0.0.
  Installing Microsoft.AspNetCore.Mvc.ApiExplorer 2.0.0.
  Installing Microsoft.AspNetCore.Localization 2.0.0.
  Installing Microsoft.AspNetCore.Identity.EntityFrameworkCore 2.0.0.
  Installing Microsoft.AspNetCore.Authorization 2.0.0.
  Installing Microsoft.AspNetCore.Http.Features 2.0.0.
  Installing Microsoft.AspNetCore.Cryptography.Internal 2.0.0.
  Installing Microsoft.AspNetCore.Cors 2.0.0.
  Installing Microsoft.AspNetCore.DataProtection.Abstractions 2.0.0.
  Installing Microsoft.AspNetCore.Authentication.OpenIdConnect 2.0.0.
  Installing Microsoft.AspNetCore.CookiePolicy 2.0.0.
  Installing Microsoft.AspNetCore.Cryptography.KeyDerivation 2.0.0.
  Installing Microsoft.AspNetCore.Authorization.Policy 2.0.0.
  Installing Microsoft.AspNetCore.Diagnostics.Abstractions 2.0.0.
  Installing Microsoft.AspNetCore.AzureAppServicesIntegration 2.0.0.
  Installing Microsoft.AspNetCore.Localization.Routing 2.0.0.
  Installing Microsoft.AspNetCore.Authentication.Twitter 2.0.0.
  Installing Microsoft.AspNetCore.Authentication.OAuth 2.0.0.
  Installing Microsoft.AspNetCore.Authentication.MicrosoftAccount 2.0.0.
  Installing Microsoft.Extensions.Hosting.Abstractions 2.0.0.
  Installing Microsoft.AspNetCore.Authentication.Cookies 2.0.0.
  Installing Microsoft.EntityFrameworkCore.Relational 2.0.0.
  Installing Microsoft.AspNetCore.Server.HttpSys 2.0.0.
  Installing Microsoft.EntityFrameworkCore.Tools 2.0.0.
  Installing Microsoft.AspNetCore.Mvc.Formatters.Xml 2.0.0.
  Installing Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions 2.0.0.
  Installing Microsoft.AspNetCore.Routing.Abstractions 2.0.0.
  Installing Microsoft.AspNetCore.Razor.Language 2.0.0.
  Installing Microsoft.AspNetCore.DataProtection.AzureStorage 2.0.0.
  Installing Microsoft.AspNetCore.Hosting.Abstractions 2.0.0.
  Installing Microsoft.Extensions.Localization 2.0.0.
  Installing Microsoft.AspNetCore.MiddlewareAnalysis 2.0.0.
  Installing Microsoft.AspNetCore.Mvc.ViewFeatures 2.0.0.
  Installing Microsoft.AspNetCore.Hosting.Server.Abstractions 2.0.0.
  Installing Microsoft.AspNetCore.Diagnostics 2.0.0.
  Installing Microsoft.AspNetCore.Authentication.JwtBearer 2.0.0.
  Installing Microsoft.AspNetCore.Owin 2.0.0.
  Installing Microsoft.AspNetCore.Authentication.Core 2.0.0.
  Installing Microsoft.AspNetCore.Authentication.Google 2.0.0.
  Installing Microsoft.AspNetCore.Authentication.Abstractions 2.0.0.
  Installing Microsoft.AspNetCore.Routing 2.0.0.
  Installing Microsoft.AspNetCore.Hosting 2.0.0.
  Installing Microsoft.AspNetCore.Mvc 2.0.0.
  Installing Microsoft.AspNetCore.Authentication 2.0.0.
  Installing Microsoft.AspNetCore.Antiforgery 2.0.0.
  Installing Microsoft.AspNetCore.ApplicationInsights.HostingStartup 2.0.0.
  Installing Microsoft.AspNetCore.AzureAppServices.HostingStartup 2.0.0.
  Installing Microsoft.AspNetCore.Server.IISIntegration 2.0.0.
  Installing Microsoft.AspNetCore.Server.Kestrel 2.0.0.
  Installing Microsoft.AspNetCore 2.0.0.
  Installing Microsoft.AspNetCore.Server.Kestrel.Https 2.0.0.
  Installing Microsoft.AspNetCore.All 2.0.0.
  Generating MSBuild file /src/WebApp1/obj/WebApp1.csproj.nuget.g.props.
  Generating MSBuild file /src/WebApp1/obj/WebApp1.csproj.nuget.g.targets.
  Restore completed in 6.87 sec for /src/WebApp1/WebApp1.csproj.
Removing intermediate container 36763ba9c396
  ---> ee8c5c57438c
Step 9/17 : COPY . .
  ---> 33ea78c746de
Step 10/17 : WORKDIR /src/WebApp1
Removing intermediate container 6ecb9f4e6d4d
  ---> 19720c9e8bf0
Step 11/17 : RUN dotnet build -c Release -o /app
  ---> Running in 24c321df6039
Microsoft (R) Build Engine version 15.5.180.51428 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 32.37 ms for /src/DockerDeployToAppServices/DockerDeployToAppServices.csproj.
  Restore completed in 11.91 ms for /src/DockerDeployToAppServices/DockerDeployToAppServices.csproj.
  DockerDeployToAppServices -> /app/DockerDeployToAppServices.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:04.15
Removing intermediate container 24c321df6039
  ---> cc75478ddcbd
Step 12/17 : FROM build AS publish
  ---> cc75478ddcbd
Step 13/17 : RUN dotnet publish -c Release -o /app
  ---> Running in 94d97edc8747
Microsoft (R) Build Engine version 15.5.180.51428 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 34.93 ms for /src/MyFirstContainer/WebApp1.csproj.
  Restore completed in 28.19 ms for /src/MyFirstContainer/WebApp1.csproj.
  WebApp1-> /src/MyFirstContainer/bin/Release/netcoreapp2.0/WebApp1.dll
  WebApp1-> /app/
Removing intermediate container 94d97edc8747
  ---> 8203313e94a4
Step 14/17 : FROM base AS final
  ---> 7a79975eb640
Step 15/17 : WORKDIR /app
  ---> Using cache
  ---> 2907b766c8a8
Step 16/17 : COPY --from=publish /app .
  ---> 60a1c5e968ac
Step 17/17 : ENTRYPOINT ["dotnet", "WebApp1.dll"]
  ---> Running in 7971f6ac5ddb
Removing intermediate container 7971f6ac5ddb
  ---> 7ef989ef71cb
Successfully built 7ef989ef71cb
Successfully tagged myfirstcontainer:latest

Popular posts from this blog

Podman– Command execution failed with exit code 125

After updating WSL on one of the developer machines, Podman failed to work. When we took a look through Podman Desktop, we noticed that Podman had stopped running and returned the following error message: Error: Command execution failed with exit code 125 Here are the steps we tried to fix the issue: We started by running podman info to get some extra details on what could be wrong: >podman info OS: windows/amd64 provider: wsl version: 5.3.1 Cannot connect to Podman. Please verify your connection to the Linux system using `podman system connection list`, or try `podman machine init` and `podman machine start` to manage a new Linux VM Error: unable to connect to Podman socket: failed to connect: dial tcp 127.0.0.1:2655: connectex: No connection could be made because the target machine actively refused it. That makes sense as the podman VM was not running. Let’s check the VM: >podman machine list NAME         ...

Cache stampede: when our cache turned against us

While investigating some performance issues, we ran into an ASP.NET Core API that cached a fairly expensive aggregation query for 60 seconds. Under normal load, that was fine: one request rebuilds the cache, everyone else reads from it. Under peak load, dozens of requests would arrive in that same expiry window, all see a cache miss, and all fire the same expensive query in parallel. The database didn't like that. That was the moment when our caching layer stopped helping and started hurting. A burst of requests comes in at the same time, all miss the cache, and all go hammer the database or the downstream API at once. That's a cache stampede . The cache was supposed to protect our backend, and for a few hundred milliseconds it did the opposite. Why this happens IMemoryCache.GetOrCreate (and its async sibling) looks like it protects you, but it doesn't add any locking on its own. Look at the naive version: public async Task<Report> GetReportAsync(string key) ...

The role of ActivitySource in OpenTelemetry for .NET

While doing some pair programming to integrate OpenTelemetry tracing to a .NET application, we had a discussion on how to use the ActivitySource . It looks simple. You new one up, give it a name, start an activity, done. The discussion started when we added a second ActivitySource with the exact same name in a different class. This made us wonder: "Are we duplicating traces now? Is this a memory leak? Do we need a singleton?" So we decided to dig deeper. This post is what we learned… What ActivitySource actually is ActivitySource is part of System.Diagnostics , not part of the OpenTelemetry NuGet packages. Microsoft built tracing primitives directly into the BCL, and OpenTelemetry's .NET SDK simply listens to them. This is why you can add distributed tracing to a library without taking a dependency on OpenTelemetry at all. An ActivitySource is a factory for Activity objects, and an Activity is .NET's name for what OpenTelemetry calls a span.(don’t ask m...