For best practices, see Use HttpClientFactory to implement resilient HTTP requests. In production code, you shouldn't dispose HttpClient after every request. Request.RequestUri = new Uri(" var response = await client.SendAsync(request) Call *mywebapi*, and display its response in the page In the DockerDemoFrontEnd project, open the Pages/ file, and replace the OnGet method with the following code: public async Task OnGet() We now have two ASP.NET projects in our solution and both are configured with Docker support. Image: $dockerdemofrontendÄockerfile: DockerDemoFrontEnd/Dockerfile When we build and run the docker-compose project, each of these projects will be deployed to a separate Docker container. The docker-compose.yml file in the docker-compose project will be automatically updated to include the API project alongside the existing Web App project. Once created, go to the Solution Window and right click the MyWebAPI project and select Add > Add Docker Support.Enter the project details, such as Project Name ( MyWebAPI in this example).Under Web and Console > App choose the API template.Add a new project to the existing solution by right-clicking on the solution and choosing Add > Add New Project.NET Core API template includes a controller that allows us to handle RESTful requests. Next we will create a second project which will act as our backend API. Create an ASP.NET Core Web API and Add Docker Support Visual Studio for Mac will automatically add a new project to your solution called docker-compose and add a Dockerfile to your existing project. In the Solution Window, right click the DockerDemoFrontEnd project and select Add > Add Docker Support:.The created project contains all the basics you need to build and run an ASP.NET Core web site. Enter the project details, such as Project Name ( DockerDemoFrontEnd in this example) and Solution Name ( DockerDemo).Under Web and Console > App choose the Web Application template:.Create a new solution by going to File > New Solution.PrerequisitesĬreate an ASP.NET Core Web Application and Add Docker Support
Looking for steps on the Windows version of Visual Studio, read Tutorial: Create a multi-container app with Docker Compose with Visual Studio for Windows.
In this tutorial, you'll learn how to manage more than one container and communicate between them when using Docker Compose in Visual Studio for Mac.