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
+30-7Lines changed: 30 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -66,7 +66,10 @@ Add a project to the same solution and call it *MyWebAPI*. Select **API** as the
66
66
::: moniker-end
67
67
68
68
:::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.
69
+
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**.
70
+
71
+
> [!NOTE]
72
+
> 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.
70
73
71
74

72
75
@@ -289,12 +292,24 @@ Congratulations, you're running a Docker Compose application with a custom Docke
289
292
```csharp
290
293
public async Task OnGet()
291
294
{
295
+
// Call *mywebapi*, and display its response in the page
292
296
using (var client = new System.Net.Http.HttpClient())
293
297
{
294
-
// Call *mywebapi*, and display its response in the page
295
298
var request = new System.Net.Http.HttpRequestMessage();
296
-
// webapi is the container name
297
-
request.RequestUri = new Uri("http://webapi/Counter");
299
+
300
+
// A delay is a quick and dirty way to work around the fact that
301
+
// the mywebapi service might not be immediately ready on startup.
302
+
// See the text for some ideas on how you can improve this.
303
+
await System.Threading.Tasks.Task.Delay(10000);
304
+
305
+
// mywebapi is the service name, as listed in docker-compose.yml.
306
+
// Docker Compose creates a default network with the services
307
+
// listed in docker-compose.yml exposed as host names.
308
+
// The port 8080 is exposed in the WebAPI Dockerfile.
309
+
// If your WebAPI is exposed on port 80 (the default for HTTP, used
310
+
// with earlier versions of the generated Dockerfile), change
311
+
// or delete the port number here.
312
+
request.RequestUri = new Uri("http://mywebapi:8080/Counter");
ViewData["Message"] = $"Counter value from cache :{counter}";
@@ -305,6 +320,12 @@ Congratulations, you're running a Docker Compose application with a custom Docke
305
320
> [!NOTE]
306
321
> 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
322
323
+
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.
324
+
325
+
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.
326
+
327
+
The delay is used here because this example code could run immediately on application launch, before the MyWebAPI service is ready to receive calls. Docker Compose provides more robust ways to handle timing issues between dependent containers that can occur during startup. For example, you can use `depends_on` to control the order in which containers are started, and you can specify a health check or other conditions that must be met before a service is considered ready, before starting the next service. See [Control startup order in Docker Compose](https://docs.docker.com/compose/how-tos/startup-order).
328
+
308
329
1. In the `Index.cshtml` file, add a line to display `ViewData["Message"]` so that the file looks like the following code:
309
330
310
331
```cshtml
@@ -329,7 +350,11 @@ Congratulations, you're running a Docker Compose application with a custom Docke
329
350
330
351
1. Choose **Docker Compose**.
331
352
332
-
1. Choose your Target OS, for example, Linux.
353
+
1. **Visual Studio 17.12 and later** Choose the scaffolding options for the WebFrontEnd project.
354
+
355
+

356
+
357
+
**Visual Studio 17.11 and earlier** Choose your Target OS, for example, Linux.
333
358
334
359

335
360
@@ -348,8 +373,6 @@ Congratulations, you're running a Docker Compose application with a custom Docke
348
373
dockerfile: WebFrontEnd/Dockerfile
349
374
```
350
375
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
376
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
377
355
378
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