Menu
Overview
I just got a MacBook Pro and am trying to run a dotnet core web api project I created on my Windows PC. I also am learning how to use Docker and am trying to integrate it into my project. Visual Studio 2017 has excellent support for Docker built-in so it offers much greater productivity and saves you from mucking with dockerfiles and the CLI directly. Visual Studio Code, on the other hand, is not nearly as refined at the moment and requires a much more hands-on approach. Visual Studio for Mac is a new IDE experience built specifically for the Mac, not a direct port of Visual Studio on Windows. This means that the UI is built to feel like you would expect working with a macOS targeted application, from primitive elements like buttons and text to the layout of the application and icons. Developer Community for Visual Studio Product family. Visual Studio. Visual Studio. Visual Studio Home. Unable to run Docker project. Reported by Zhen Liu May 15. Could not create a new solution on Visual Studio for Mac 0 Solution VS for mac with voiceover 0 Solution. Missing Add Docker Support. Reported by Mike Palmer Feb 19 at 10:48 AM visual studio for mac. Upgraded to the new version of Visual Studio for Mac and the Add Docker Support menu item is missing. Reverted back to v12, created WebAPI and menu item is available. Rolled forward, same exercise and it is missing.
Microsoft offers great support for building apps deployed to Docker containers in Visual Studio for Mac, that can be easily deployed and managed in Azure. With the power of the cloud behind your solution, you can easily compose powerful constellations of these containers known as 'microservices' that are independently managed and scaled. Visual studio for mac console application. In this hands-on lab you will create a microservices solution that employs two ASP.NET Core apps hosted in separate Docker containers.
Objectives
- Create an ASP.NET Core web site
- Deploy the site in a Docker container
- Create and integrate an ASP.NET Core web API project in a Docker container
Prerequisites
- Visual Studio for Mac (https://www.visualstudio.com/vs/visual-studio-mac)
- Note that this lab currently requires switching to the Alpha channel in Visual Studio for Mac, as Docker support is available as a preview
- Docker (https://go.microsoft.com/fwlink/?linkid=847268)
Intended Audience
This lab is intended for developers who are familiar with C# and ASP.NET, although deep experience is not required.
Exercise 1: Getting started integrating with Docker containers in Visual Studio for Mac
![Visual studio for mac docker compose Visual studio for mac docker compose](https://devopshub.cn/wp-content/uploads/2016/07/d4d-3-docker-for-mac.png)
Task 1: Creating an ASP.NET Core web site and enabling it for Docker
- Launch Visual Studio for Mac.
- Select File > New Solution.
- Select the .NET Core > App category and the ASP.NET Core Web App template. Click Next.
- If presented with a Target Framework selection screen for .NET Core, select the target framework you want to use, such as .NET Core 1.1. Click Next.
- Enter a Project Name of 'DockerLab' and click Create.
- The created project contains all the basics you need to build and run an ASP.NET Core web site.
- In Solution Explorer, right-click the DockerLab project node and select Add > Add Docker Support. This will add a new Docker-specific project to the solution (docker-compose), along with a Docker configuration file to the project.
- Open the newly added Dockerfile from the DockerLab project.
- Dockerfile describes the application, including the base container, the port number to expose the application on, the entry point of the application, and more. You can learn more about this format here.
- From the docker-compose project, open docker-compose.yml.
- docker-compose.yml describes how the application should be composed of the required containers to set up a given solution. Right now, there's just one service for the DockerLab project created earlier. More will be added here as additional container apps become part of the solution.
- Note that the docker-compose project has also become the default startup project. This makes it easy to launch multiple projects as part of the same debugging session.
- Select Run > Start Debugging or press F5 to build, deploy, and run the project in a Docker container. This may take a minute or so to complete.
- Once the application has launched in Safari, note that the URL is to the specific localhost port the container is listening on (it may vary from the screenshot below).
- Open a new instance of Terminal.
- Execute the command below to get a list of all Docker containers running.
- Unless you have other containers running, there should be only one. Note that the data wraps into three lines in the screenshot below. Xamarin build ios from windows. A key point of interest is the port relay that indicates that the container is listening on a given port (which should be the same as used by the browser above) and using port 80 to reach its internal web server. As far as the app knows, it's listening on port 80.
Task 2: Creating an ASP.NET Core Web API and enabling it for Docker
- Return to Visual Studio for Mac and stop debugging.
- In Solution Explorer, right-click the DockerLab solution node (the top-most node) and select Add > Add New Project.
- Select the .NET Core > App category and the ASP.NET Core Web API project template. Rather than including some basic web application files to render HTML, this template includes a controller designed to handle RESTful requests. Click Next.
- If presented with a Target Framework selection screen for .NET Core, select the target framework you want to use, such as .NET Core 1.1. Click Next.
- Enter a project name of 'api' and click Create.
- The project structure of the API project is similar to the web site project, except that it has fewer files since it doesn't need views or some of the client-side web components. It still uses MVC, so the Controllers folder is where the magic happens.
- Right-click the api project node and select Add > Add Docker Support. This will run the same process as before, but will now merge new settings for this project alongside the existing settings for the DockerLab project.
- Close and reopen docker-compose.yml to refresh the changes.
- Now you will see that the second API project has been added alongside the web application. When built and run, they will be deployed to separate Docker containers and able to access each other as configured.
![Visual Studio For Mac Docker Visual Studio For Mac Docker](/uploads/1/2/6/8/126885475/675506016.png)
Task 3: Integrating two container apps
- From the api project, open Controllers/ValuesController.cs. This is the default controller that contains a configured API you can edit.
- Replace the first Get method with the code below. This is just a minor change to make the API easier to consume for our lab purposes. Do not remove the [HttpGet] attribute.
- Your inserted code should look like this.
- Set a breakpoint on the return line of code. You can do this by clicking in the margin or by setting the cursor somewhere on the line and pressing F9.
- From the DockerLab project, open Controllers/HomeController.cs. This controller manages the content rendered for the default pages in the project.
- In the About method, replace the first line referencing ViewData with the code below. This code integrates with the API you just edited in the API project and displays the result. This is a practical approach for the purposes of this lab and not a proper practice for more robust applications.
- Set a breakpoint on the return line of this method.
Docker With Visual Studio
Task 4: Debugging multi-container solutions
- Press F5 to build and run the project. When the browser window loads, two Docker containers will be running.
- In Terminal, execute the command below to view the containers.
- The two containers with their details will be displayed. Fruit loop studio for mac. Note that the data wraps to three lines each.
- In the browser, navigate to the About page.
- Visual Studio for Mac will hit two breakpoints during this request. Press F10 to step through each execution as the API request is returned to the web app (across Docker containers!) and rendered. You will eventually see the result of 'API' that was returned from the API displayed from the web app.
- Refresh the page in the browser. This will hit the first breakpoint once again.
- This time, open the Locals pad and locate the message variable. It should have the value of 'API' since that was the most recently executed line of code.
- Double-click the value and change it to 'changed' (with quotes). Press Enter to apply.
- Press F5 to continue execution.
- The next stop will be in the container hosting the web app, where you will see the returned value. This time it should reflect 'changed'. Press F5 to continue execution once again.
- The new API value should render out as HTML in the browser. This multi-container microservices solution is now ready to be extended and deployed.
Summary
Visual Studio For Mac Docker Install
In this lab, you've learned how to get started integrating with Docker containers with Visual Studio for Mac.