10

In Visual Studio 2017 I am working on a project with 3 dotnet core projects. It was building and starting the containers using docker-compose as the startup project. Now it is giving me an error that it cannot find the container starting with a given name. In the Output window in the Show output from: docker selected it shows the combined docker-compose.yml files.

It appears that it is not building the containers, hence why it cannot find the container it is looking for by name. After seeing this I ran all the docker commands in PowerShell and it built the images and started the containers right up. With the containers in place Visual Studio started, but gave me a different error.

I'm wondering why Visual Studio would not be building the containers anymore.

Note: I have had trouble in the past when spinning up the containers using docker cli that Visual Studio would throw exceptions, but I have cleaned docker running containers, network, volume, and images...

enter image description here

Thanks for your help in advance. I am loving docker, but there are some frustrations when using the VS tools thus far...

CarBar
  • 145
  • 2
  • 7
  • I also encounter the same issue, when I run a new ASP.NET Core 2 app with Linux container inside VS2017 15.6.6. It was working a couple of days ago. – Win Apr 21 '18 at 16:45
  • VStudio Docker support is pretty sub-par unfortunately. If the container has been stopped, VS.NET doesn't know how to restart it. Sometimes editing the docker-compose.yml file and rebuilding helps get it to run correctly again. – willem Dec 21 '18 at 07:14

3 Answers3

10

Make sure that in Build > Configuration Manager that you have the Docker project set to build in Debug mode - this being unticked caused this issue for me and re-ticking it proved to be the solution.

DenverCoder9
  • 1,119
  • 3
  • 16
  • 30
9

In my case I had Resharper's build enabled, which confused Visual Studio. Switching to normal Visual Studio build in Resharper -> Options -> Tools -> Build solved the problem for me.

It also helps sometimes to right-click on the docker-compose item in Visual Studio, then choosing "Clean". This causes Visual Studio to call docker-compose kill, giving you a fresh slate. Note that the output from this process appears in the "Build" window, not the "Docker" one.

willem
  • 25,977
  • 22
  • 75
  • 115
  • Wow, this has been plaguing me for a while. Thanks a lot for the Clean and its behind-the-scenes magic in a docker context! – Veverke Jul 27 '22 at 14:24
0

Are you running the project by clicking the 'Docker" button at the top of the VS2017 window? This should build and run the correct container.

  • 1
    I was trying to press the "Docker" play button at the top. However this is where the issue is. One of the people on the project removed the docker project from building. This was part of the problem and has been fixed, but it still doesn't work with the play button. However if I right click on the Docker project itself select build, then go to Debug > Start New Instance then it works fine. – CarBar Apr 28 '17 at 04:33