15

I have moved the docker file from *.csproj folder to .sln folder i.e., one level up. When I try to docker build using visual studio 2019, I get bellow error but same project docker build works from command prompt. Not sure what is causing visual studio 2019 to throw this error. Any help to solve this error would be helpful.

Error: No Dockerfile could be found. Please make sure you have a Dockerfile called 'Dockerfile' adjacent to the project file.

error from VS-2019

Docker build works from commands prompt :

works from command prompt

alphacoder
  • 553
  • 2
  • 9
  • 21
  • Is the docker build command running from the same directory in visual studio? Since you moved the file, that’s what I would guess – C.Nivs Oct 20 '19 at 04:22
  • Yes, if I keep the dockerfile in the same folder, docker build works , How do I make sure it works even if I move it up at the solution file level? – alphacoder Oct 21 '19 at 16:53

2 Answers2

33

You can specify the path to the Dockerfile using the DockerfileFile property.

  1. Start Visual Studio 2019 as Admin (necessary in my case)
  2. Edit targeted .csproj
  3. Add the DockerfileFile attribute with the relative path (parent folder in my case)
  4. Keep the DockerfileContext as is.

Example csproj configuration:

<PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <UserSecretsId>secretstuff</UserSecretsId>
    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
    <DockerfileContext>.</DockerfileContext>
    <DockerfileFile>..\Dockerfile</DockerfileFile>    
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
  1. Start the project in Debug mode with Docker (F5).
Dave
  • 2,774
  • 4
  • 36
  • 52
  • 2
    Thanks! I had the same problem and this solution worked for me. The error description is misleading, it should say it cannot find Dockerfile, make sure csproj file points to dockerfile! – Bahman Sep 06 '20 at 23:15
-2

In VS right click on the project, select "Add", then "Docker Support". VS will add the file, config and start downloading the required docker image files