The Windows Containers tooling is great! It simplifies the process of containerizing your applications, generating Docker and Compose files and giving you the full Docker CLI (command line interface) with the same API that you would use for Linux containers.
That said, you may come across a problem where Visual Studio cannot connect to underlying Windows container. Error messages can manifest themselves in a couple of ways:
Error response from daemon: Container is not running.
Unable to start debugging on the web server. The Visual Studio 2017 Remote Debugger (MSVSMON.EXE) does not appear to be running on the remote computer.
Good chance the container is running just fine, but Visual Studio (or, Windows, for that matter) cannot connect to it. If you were to type, “Docker exec -it <container id> cmd”, from a command prompt, you might just be able to connect to the running container and execute commands against it. For example, typing “powershell wget http://localhost -UseBasicParsing” might dump the contents of your home page, including an HTTP status code of 200.
Now for the fun part, getting Windows to see the container.
If you were to spend many hours of troubleshooting, you might come to realize that you are missing a virtual Ethernet adapter, entitled the HNS Internal NIC. If your Docker tooling was running correctly, you would see the virtual HNS adapter by typing IPCONFIG/ ALL as shown below.
However, you don’t see it.
Now, the question becomes, how do I get this virtual adapter?
From a command prompt, type “ncpa.cpl“. This will open the Network Connections Window. Note below (in red) how the HNS adapter is present, but disabled (perhaps to a Windows update or such).
Simply, right click the HNS Internal NIC (in red, above) and select Enable, and you should be back in business.
Go ahead and use Visual Studio to containerize a simple web application, step into in a debugging session and you should be able to connect to the container and debug the application just fine.
Rob Vettor is a Senior Developer Consultant with Microsoft, helping Microsoft Enterprise customers construct high-quality software. Rob focuses on Azure PaaS, including the Service Fabric and Azure App Services platforms. A former user group leader, 3-time C# MVP and co-author of the book Entity Framework 6 Recipes, Rob is a frequent presenter at technical conferences. Reach out at firstname.lastname@example.org.