Docker in Visual Studio 2017

Visual Studio 2017 has the most complete Docker support of all the .NET IDEs. You can open an ASP.NET Framework Web API project in Visual Studio 2017, right-click on the project, and select Add | Container Orchestrator Support:

There's only one orchestrator option to choose from, which is Docker Compose. Visual Studio then generates a set of Docker artifacts. In the Web project, it creates a Dockerfile that looks like this:

FROM microsoft/aspnet:4.7.2-windowsservercore-1803
ARG source
WORKDIR /inetpub/wwwroot
COPY ${source:-obj/Docker/publish} .

There's full IntelliSense support for the Dockerfile syntax, so you can hover over instructions and see information about them and use Ctrl + Spacebar to open a prompt for all Dockerfile instructions.

The generated Dockerfile uses the microsoft/aspnet base image, which comes with ASP.NET 4.7.2, fully installed and configured. At the time of writing, the Dockerfile uses an old version of the Windows base image, so you need to manually update it to use the latest Windows Server 2019 base image, that is, mcr.microsoft.com/dotnet/framework/aspnet:4.7.2-windowsservercore-ltsc2019.

The Dockerfile looks odd because it uses a build argument to specify the location of the source folder, and then it copies the content of that folder to the web root directory, C:inetpubwwwroot, inside the container image.

In the solution root, Visual Studio creates a set of Docker Compose files. There are multiple files, and Visual Studio uses them with the Docker Compose build and up commands to package and run the application. This works behind the scenes when you run the app with the F5 key , but it's worth looking at how Visual Studio uses them; it shows you how you can add this level of support to different IDEs.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.255.36