You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/containers/tutorial-multicontainer.md
+32-14Lines changed: 32 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,15 +45,9 @@ Don't select **Enable Docker Support**. You add Docker support later in the proc
45
45
::: moniker-end
46
46
::: moniker range=">=vs-2022"
47
47
48
-
> [!NOTE]
49
-
> In Visual Studio 2022 17.2 and later, you can use Azure Functions for this project instead.
50
-
51
-

52
-
53
48
Don't select **Enable Docker Support**. You add Docker support later in the process.
54
49
55
-

56
-
50
+

57
51
::: moniker-end
58
52
59
53
## Create a Web API project
@@ -66,7 +60,10 @@ Add a project to the same solution and call it *MyWebAPI*. Select **API** as the
66
60
::: moniker-end
67
61
68
62
:::moniker range=">=vs-2022"
69
-
1. Add a project to the same solution and call it *WebAPI*. Select **API** as the project type, and clear the checkbox for **Configure for HTTPS**. In this design, we're only using SSL for communication with the client, not for communication from between containers in the same web application. Only `WebFrontEnd` needs HTTPS and the code in the examples assumes that you have cleared that checkbox. In general, the .NET developer certificates used by Visual Studio are only supported for external-to-container requests, not for container-to-container requests.
63
+
1. Add a project to the same solution and call it *MyWebAPI*. Select **API** as the project type, and clear the checkbox for **Configure for HTTPS**.
64
+
65
+
> [!NOTE]
66
+
> In this design, we're only using HTTPS for communication with the client, not for communication from between containers in the same web application. Only `WebFrontEnd` needs HTTPS and the code in the examples assumes that you have cleared that checkbox. In general, the .NET developer certificates used by Visual Studio are only supported for external-to-container requests, not for container-to-container requests.
70
67
71
68

72
69
@@ -289,12 +286,25 @@ Congratulations, you're running a Docker Compose application with a custom Docke
289
286
```csharp
290
287
public async Task OnGet()
291
288
{
289
+
// Call *mywebapi*, and display its response in the page
292
290
using (var client = new System.Net.Http.HttpClient())
293
291
{
294
-
// Call *mywebapi*, and display its response in the page
295
292
var request = new System.Net.Http.HttpRequestMessage();
296
-
// webapi is the container name
297
-
request.RequestUri = new Uri("http://webapi/Counter");
293
+
294
+
// A delay is a quick and dirty way to work around the fact that
295
+
// the mywebapi service might not be immediately ready on startup.
296
+
// See the text for some ideas on how you can improve this.
ViewData["Message"] = $"Counter value from cache :{counter}";
@@ -305,6 +315,12 @@ Congratulations, you're running a Docker Compose application with a custom Docke
305
315
> [!NOTE]
306
316
> In real-world code, you shouldn't dispose `HttpClient` after every request. For best practices, see [Use HttpClientFactory to implement resilient HTTP requests](/dotnet/architecture/microservices/implement-resilient-applications/use-httpclientfactory-to-implement-resilient-http-requests).
307
317
318
+
The Uri given references a service name defined in the *docker-compose.yml* file. Docker Compose sets up a default network for communication between containers using the listed service names as hosts.
319
+
320
+
The code shown here works with .NET 8 and later, which sets up a user account in the Dockerfile without administrator privileges, and exposes port 8080 because the HTTP default port 80 is not accessible without elevated privilege.
321
+
322
+
The delay is used here as a workaround for .NET 8 only, because this example code could run immediately on application launch, before the MyWebAPI service is ready to receive web requests.
323
+
308
324
1. In the `Index.cshtml` file, add a line to display `ViewData["Message"]` so that the file looks like the following code:
309
325
310
326
```cshtml
@@ -329,7 +345,11 @@ Congratulations, you're running a Docker Compose application with a custom Docke
329
345
330
346
1. Choose **Docker Compose**.
331
347
332
-
1. Choose your Target OS, for example, Linux.
348
+
1. **Visual Studio 17.12 and later** Choose the scaffolding options for the WebFrontEnd project.
349
+
350
+

351
+
352
+
**Visual Studio 17.11 and earlier** Choose your Target OS, for example, Linux.
333
353
334
354

335
355
@@ -348,8 +368,6 @@ Congratulations, you're running a Docker Compose application with a custom Docke
348
368
dockerfile: WebFrontEnd/Dockerfile
349
369
```
350
370
351
-
The `version` specified in the first line is the [Docker Compose file version](https://docs.docker.com/compose/compose-file/#version-top-level-element). You normally shouldn't change it, since it's used by the tools to understand how to interpret the file.
352
-
353
371
The `.dockerignore` file contains file types and extensions that you don't want Docker to include in the container. These files are generally associated with the development environment and source control, not part of the app or service you're developing.
354
372
355
373
Look at the **Container Tools** section of the output pane for details of the commands being run. You can see the command-line tool `docker-compose` is used to configure and create the runtime containers.
0 commit comments