Visual studio container tools require docker desktop

Question:

I am working on .Net core Microservices. I installed Docker Toolbox containing docker cli and kitematics. After that i created a simple (.Net core) web api project in visual studio 2017 and also enable docker support.

But when i hit F5 to run the program it shows following error and doesn’t run.

Visual Studio Container Tools requires Docker to be running before building, debugging or running a containerized project.

Please review the attached image.

Visual studio error on running the project

Visual studio container tools require docker desktop

If i build and run the project using docker cli, it’s working. The problem is with visual studio 2017.

Answer:

The problem occurs because Visual studio container is unable to connect to docker for windows and solution for this is to open the visual studio 2017 from Docker CLI using following command.
/c/Program\ Files\ \(x86\)/Microsoft\ Visual\ Studio/2017/Community/Common7/IDE/devenv.exe C:\\PATH\\TO\\MY\\SOLUTION.sln

Here:

C:\Program Files(x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\devenv.exe

is the location of my devenv.exe file and 2nd parameter

C:\\PATH\\TO\\MY\\SOLUTION.sln

shows the path of solution file.

For further details of this solution, click Here.

I've been doing more and more work in Docker containers (rather than on the metal) and I noticed recently that Visual Studio 2019 added updated support for containers within VS itself so gave it a try.

When you make a new ASP.NET Core web app, make sure to check "enable docker support" when you click create.

Visual studio container tools require docker desktop

You'll need Docker for Windows first, of course. I'm using the new Docker Desktop for Windows that uses WSL2 for its backend rather than a utility VM that's visible in Hyper-V.

Now, within Visual Studio 2019, go to the View Menu and click "Other Windows | Containers." I like to dock this new tool window at the bottom.

Visual studio container tools require docker desktop

Note in my screenshot above I'm starting up SQL Server on Linux within a container. This window is fantastic and includes basically everything you'd want to know and see when developing within a container.

You can see the ports exposed, the container's local file system, the environment, and the logs as they happen.

Visual studio container tools require docker desktop

You can even right-click on a container and get a Terminal Window into that running container if you like:

Visual studio container tools require docker desktop

You can also see https://aka.ms/containerfastmode to understand how Visual Studio uses your multistage Dockerfile (like the one below) to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["WebApplication1/WebApplication1.csproj", "WebApplication1/"]
RUN dotnet restore "WebApplication1/WebApplication1.csproj"
COPY . .
WORKDIR "/src/WebApplication1"
RUN dotnet build "WebApplication1.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "WebApplication1.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApplication1.dll"]

Go read about the new Container Tools in Visual Studio. Chances are you have a dockerfile in your project but you haven't brought this Containers Tool Window out to play!


Sponsor: Organizations that scan their code more than 300 times a year have 5x less security debt than those with sporadic testing processes. The 2019 SOSS X report from Veracode digs into this data—and more.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

Visual studio container tools require docker desktop
Visual studio container tools require docker desktop
Visual studio container tools require docker desktop

About   Newsletter

Hosting By

Visual studio container tools require docker desktop

Does Visual Studio require Docker Desktop?

Visual Studio Container Tools requires Docker to be running before building, debugging or running a containerized project. Please review the attached image. If i build and run the project using docker cli, it's working.

Can I use Docker without Docker Desktop?

Docker Desktop is Docker (the company)'s first wedge into getting you to run proprietary software, so Docker strongly guides you to download it as the only way to get started: In fact, new users can go pretty far without even realizing that you don't need Docker Desktop to run the Docker daemon.

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 Containerize an application without Docker?

You can either use your normal container builder with OpenFaaS, or faas-cli build --shrinkwrap and pass the build-context along to your preferred tooling. Here's examples for the following tools for building OpenFaaS containers: Google Cloud Build. GitHub Actions.