Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 849
alphacoder Avatar asked Oct 20 '19 04:10

alphacoder


People also ask

How to enable Docker in visual studio?

Existing app Open the project in Visual Studio, and choose one of the following options: Select Docker Support from the Project menu. Right-click the project in Solution Explorer and select Add > Docker Support.

Can I run visual studio in a Docker container?

The Visual Studio Code Dev Containers extension lets you use a Docker container as a full-featured development environment. It allows you to open any folder inside (or mounted into) a container and take advantage of Visual Studio Code's full feature set.

How do I get rid of Docker support?

Solution. In case you'd like to entirely drop Docker support, you can even delete the Dockerfile and <projectname>. csproj. user file from your project.


1 Answers

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).
like image 180
Dave Avatar answered Oct 25 '22 04:10

Dave