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: samples/aspnetapp/README.md
+99-22Lines changed: 99 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -14,9 +14,26 @@ If want to skip ahead, you can try a pre-built version with the following comman
14
14
docker run --rm -it -p 8000:80 mcr.microsoft.com/dotnet/samples:aspnetapp
15
15
```
16
16
17
+
You can also call an endpoint that the app exposes:
18
+
19
+
```bash
20
+
$ curl http://localhost:8000/Environment
21
+
{"runtimeVersion":".NET 7.0.2","osVersion":"Linux 5.15.79.1-microsoft-standard-WSL2 #1 SMP Wed Nov 23 01:01:46 UTC 2022","osArchitecture":"X64","user":"root","processorCount":16,"totalAvailableMemoryBytes":67430023168,"memoryLimit":9223372036854771712,"memoryUsage":100577280}
22
+
```
23
+
24
+
You can see the app running via `docker ps`.
25
+
26
+
```bash
27
+
$ docker ps
28
+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
29
+
d79edc6bfcb6 mcr.microsoft.com/dotnet/samples:aspnetapp "./aspnetapp" 35 seconds ago Up 34 seconds (healthy) 0.0.0.0:8080->80/tcp nice_curran
30
+
```
31
+
32
+
You may notice that the sample includes a [health check](https://docs.docker.com/engine/reference/builder/#healthcheck), which is indicated in the "STATUS" column.
33
+
17
34
## Build an ASP.NET Core image
18
35
19
-
You can build and run a .NET-based container image using the following instructions:
36
+
You can build and run an image using the following instructions:
20
37
21
38
```console
22
39
docker build --pull -t aspnetapp .
@@ -33,10 +50,10 @@ Now listening on: http://[::]:80
33
50
Application started. Press Ctrl+C to shut down.
34
51
```
35
52
36
-
After the application starts, navigate to `http://localhost:8000` in your web browser.
37
-
38
53
> Note: The `-p` argument maps port 8000 on your local machine to port 80 in the container (the form of the port mapping is `host:container`). See the [Docker run reference](https://docs.docker.com/engine/reference/commandline/run/) for more information on command-line parameters. In some cases, you might see an error because the host port you select is already in use. Choose a different port in that case.
39
54
55
+
After the application starts, navigate to `http://localhost:8000` in your web browser.
56
+
40
57
You can also view the ASP.NET Core site running in the container on another machine. This is particularly useful if you are wanting to view an application running on an ARM device like a Raspberry Pi on your network. In that scenario, you might view the site at a local IP address such as `http://192.168.1.18:8000`.
41
58
42
59
In production, you will typically start your container with `docker run -d`. This argument starts the container as a service, without any console interaction. You then interact with it through other Docker commands or APIs exposed by the containerized application.
@@ -45,35 +62,64 @@ We recommend that you do not use `--rm` in production. It cleans up container re
45
62
46
63
> Note: See [Establishing docker environment](../establishing-docker-environment.md) for more information on correctly configuring Dockerfiles and `docker build` commands.
47
64
48
-
## Build an image for Windows Nano Server
65
+
## Build an image with `HEALTHCHECK`
49
66
50
-
The following example demonstrates targeting Windows Nano Server (x64) explicitly (you must have [Windows containers enabled](https://docs.docker.com/docker-for-windows/#switch-between-windows-and-linux-containers)):
67
+
The sample uses [ASP.NET Core Health Check middleware](https://learn.microsoft.com/aspnet/core/host-and-deploy/health-checks). You can direct Docker, Kubernetes, or other systems to use the ASP.NET Core `healthz` endpoint.
docker run --rm -it -p 8000:80 aspnetapp:nanoserver
55
-
```
69
+
The [`HEALTHCHECK`](https://docs.docker.com/engine/reference/builder/#healthcheck) directive is implemented in the [`Dockerfile.alpine-slim`](Dockerfile.alpine-slim) and [`Dockerfile.nanoserver`](Dockerfile.nanoserver-slim). You can build those via the same pattern.
56
70
57
-
You can view in the app in your browser in the same way as demonstrated earlier.
You can use `docker images` to see the images you've built:
76
+
In another terminal:
60
77
61
-
```console
62
-
> docker images aspnetapp
63
-
REPOSITORY TAG IMAGE ID CREATED SIZE
64
-
aspnetapp latest b2f0ecb7bdf9 About an hour ago 353MB
65
-
aspnetapp nanoserver d4b7586827f2 About an hour ago 353MB
78
+
```bash
79
+
$ docker ps
80
+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
81
+
b143cf4ac0d1 aspnetapp "./aspnetapp" 8 seconds ago Up 7 seconds (health: starting) 0.0.0.0:8000->80/tcp fervent_lichterman
66
82
```
67
83
68
-
## Build an image for Windows Server Core
84
+
After 30s, the status should transition to "healthy" from "health: starting".
85
+
86
+
You can also look at health status with `docker inspect`. The following pattern uses `jq`, which makes it much easier to drill in on the interesting data.
The instructions for Windows Server Core are very similar to Windows Nano Server. There are three different sample Dockerfile files provided for Windows Server Core, which can all be used with the same approach as the Nano Server ones.
110
+
The same thing can be accomplished with PowerShell.
71
111
72
-
In addition, one of the samples enables using IIS as the Web Server instead of Kestrel. The following example demonstrates using that Dockerfile.
@@ -113,6 +159,37 @@ aspnetapp latest 8c5d1952e3b7 10 hours ago
113
159
114
160
You can run these images in the same way as is done above, with Alpine.
115
161
162
+
## Build an image for Windows Nano Server
163
+
164
+
The following example demonstrates targeting Windows Nano Server (x64) explicitly (you must have [Windows containers enabled](https://docs.docker.com/docker-for-windows/#switch-between-windows-and-linux-containers)):
docker run --rm -it -p 8000:80 aspnetapp:nanoserver
169
+
```
170
+
171
+
You can view in the app in your browser in the same way as demonstrated earlier.
172
+
173
+
You can use `docker images` to see the images you've built:
174
+
175
+
```console
176
+
> docker images aspnetapp
177
+
REPOSITORY TAG IMAGE ID CREATED SIZE
178
+
aspnetapp latest b2f0ecb7bdf9 About an hour ago 353MB
179
+
aspnetapp nanoserver d4b7586827f2 About an hour ago 353MB
180
+
```
181
+
182
+
## Build an image for Windows Server Core
183
+
184
+
The instructions for Windows Server Core are very similar to Windows Nano Server. There are three different sample Dockerfile files provided for Windows Server Core, which can all be used with the same approach as the Nano Server ones.
185
+
186
+
In addition, one of the samples enables using IIS as the Web Server instead of Kestrel. The following example demonstrates using that Dockerfile.
By default, distro-specific .NET tags target x64, such as `6.0-alpine` or `6.0-focal`. You need to use an architecture-specific tag if you want to target ARM. Note that .NET is only supported on Alpine on ARM64 and x64, and not ARM32.
0 commit comments