alphacoder
alphacoder

Reputation: 573

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

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

Upvotes: 16

Views: 7609

Answers (2)

Vishal Biseswar
Vishal Biseswar

Reputation: 1

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

Upvotes: -3

Dave
Dave

Reputation: 2984

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).

Upvotes: 42

Related Questions