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
* update version in 'enabled by default'
* zone pivots and analysislevel
* .net 10 ga updates
* reset ca files
* fix zone pivot warnings
* Apply suggestions from code review
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Replace the file with the following code that counts numbers every second:
101
109
102
-
:::zone pivot="dotnet-9-0"
103
-
104
-
:::code source="snippets/9.0/App/Program.cs":::
105
-
106
-
:::zone-end
107
-
:::zone pivot="dotnet-8-0"
108
-
109
-
:::code source="snippets/8.0/App/Program.cs":::
110
-
111
-
:::zone-end
110
+
:::code source="snippets/App/Program.cs":::
112
111
113
112
Save the file and test the program again with `dotnet run`. Remember that this app runs indefinitely. Use the cancel command <kbd>Ctrl+C</kbd> to stop it. Consider the following example output:
114
113
@@ -143,8 +142,6 @@ The `dotnet publish` command compiles your app to the _publish_ folder. The path
143
142
144
143
From the _App_ folder, get a directory listing of the publish folder to verify that the _DotNet.Docker.dll_ file was created.
145
144
146
-
:::zone pivot="dotnet-9-0"
147
-
148
145
```powershell
149
146
dir .\bin\Release\net9.0\publish\
150
147
@@ -159,46 +156,15 @@ Mode LastWriteTime Length Name
159
156
-a---- 1/6/2025 10:11 AM 340 DotNet.Docker.runtimeconfig.json
@@ -207,31 +173,17 @@ The _Dockerfile_ file is used by the `docker build` command to create a containe
207
173
208
174
Create a file named _Dockerfile_ in the directory containing the _.csproj_ and open it in a text editor. This tutorial uses the ASP.NET Core runtime image (which contains the .NET runtime image) and corresponds with the .NET console application.
> The ASP.NET Core runtime image is used intentionally here, although the `mcr.microsoft.com/dotnet/runtime:8.0` image could be used instead.
224
-
225
-
:::zone-end
226
-
227
181
> [!IMPORTANT]
228
182
> Including a secure hash algorithm (SHA) after the image tag in a _Dockerfile_ is a best practice. This ensures that the image is not tampered with and that the image is the same as the one you expect. The SHA is a unique identifier for the image. For more information, see [Docker Docs: Pull an image by digest](https://docs.docker.com/reference/cli/docker/image/pull/#pull-an-image-by-digest-immutable-identifier).
229
183
230
184
> [!TIP]
231
185
> This _Dockerfile_ uses multi-stage builds, which optimize the final size of the image by layering the build and leaving only required artifacts. For more information, see [Docker Docs: multi-stage builds](https://docs.docker.com/build/building/multi-stage/).
232
186
233
-
:::zone pivot="dotnet-9-0"
234
-
235
187
The `FROM` keyword requires a fully qualified Docker container image name. The Microsoft Container Registry (MCR, mcr.microsoft.com) is a syndicate of Docker Hub, which hosts publicly accessible containers. The `dotnet` segment is the container repository, whereas the `sdk` or `aspnet` segment is the container image name. The image is tagged with `9.0`, which is used for versioning. Thus, `mcr.microsoft.com/dotnet/aspnet:9.0` is the .NET 9.0 runtime. Make sure that you pull the runtime version that matches the runtime targeted by your SDK. For example, the app created in the previous section used the .NET 9.0 SDK, and the base image referred to in the _Dockerfile_ is tagged with **9.0**.
236
188
237
189
> [!IMPORTANT]
@@ -263,37 +215,6 @@ Save the _Dockerfile_ file. The directory structure of the working folder should
263
215
└──...
264
216
```
265
217
266
-
:::zone-end
267
-
:::zone pivot="dotnet-8-0"
268
-
269
-
The `FROM` keyword requires a fully qualified Docker container image name. The Microsoft Container Registry (MCR, mcr.microsoft.com) is a syndicate of Docker Hub, which hosts publicly accessible containers. The `dotnet` segment is the container repository, whereas the `sdk` or `aspnet` segment is the container image name. The image is tagged with `8.0`, which is used for versioning. Thus, `mcr.microsoft.com/dotnet/aspnet:8.0` is the .NET 8.0 runtime. Make sure that you pull the runtime version that matches the runtime targeted by your SDK. For example, the app created in the previous section used the .NET 8.0 SDK, and the base image referred to in the _Dockerfile_ is tagged with **8.0**.
270
-
271
-
> [!IMPORTANT]
272
-
> When using Windows-based container images, you need to specify the image tag beyond simply `8.0`, for example, `mcr.microsoft.com/dotnet/aspnet:8.0-nanoserver-1809` instead of `mcr.microsoft.com/dotnet/aspnet:8.0`. Select an image name based on whether you're using Nano Server or Windows Server Core and which version of that OS. You can find a full list of all supported tags on .NET's [Docker Hub page](https://hub.docker.com/_/microsoft-dotnet).
273
-
274
-
Save the _Dockerfile_ file. The directory structure of the working folder should look like the following. Some of the deeper-level files and folders are omitted to save space in the article:
275
-
276
-
```Directory
277
-
📁 docker-working
278
-
└──📂 App
279
-
├── Dockerfile
280
-
├── DotNet.Docker.csproj
281
-
├── Program.cs
282
-
├──📂 bin
283
-
│ └──📂 Release
284
-
│ └──📂 net8.0
285
-
│ └──📂 publish
286
-
│ ├── DotNet.Docker.deps.json
287
-
│ ├── DotNet.Docker.exe
288
-
│ ├── DotNet.Docker.dll
289
-
│ ├── DotNet.Docker.pdb
290
-
│ └── DotNet.Docker.runtimeconfig.json
291
-
└──📁 obj
292
-
└──...
293
-
```
294
-
295
-
:::zone-end
296
-
297
218
The `ENTRYPOINT` instruction sets `dotnet` as the host for the `DotNet.Docker.dll`. However, it's possible to instead define the `ENTRYPOINT` as the app executable itself, relying on the OS as the app host:
Docker processes each line in the _Dockerfile_. The `.` in the `docker build` command sets the build context of the image. The `-f` switch is the path to the _Dockerfile_. This command builds the image and creates a local repository named **counter-image** that points to that image. After this command finishes, run `docker images` to see a list of images installed:
312
233
313
-
:::zone pivot="dotnet-9-0"
314
-
315
234
```console
316
235
REPOSITORY TAG IMAGE ID CREATED SIZE
317
236
counter-image latest 1c1f1433e51d 32 seconds ago 223MB
318
237
```
319
238
320
-
:::zone-end
321
-
:::zone pivot="dotnet-8-0"
322
-
323
-
```console
324
-
docker images
325
-
REPOSITORY TAG IMAGE ID CREATED SIZE
326
-
counter-image latest 2f15637dc1f6 10 minutes ago 217MB
327
-
```
328
-
329
-
:::zone-end
330
-
331
239
The `counter-image` repository is the name of the image. Additionally, the image tag, image identifier, size and when it was created are all part of the output. The final steps of the _Dockerfile_ are to create a container from the image and run the app, copy the published app to the container, and define the entry point:
332
240
333
-
:::zone pivot="dotnet-9-0"
334
-
335
241
```dockerfile
336
242
FROM mcr.microsoft.com/dotnet/aspnet:9.0
337
243
WORKDIR /App
338
244
COPY --from=build /App/out .
339
245
ENTRYPOINT ["dotnet", "DotNet.Docker.dll"]
340
246
```
341
247
342
-
:::zone-end
343
-
:::zone pivot="dotnet-8-0"
344
-
345
-
```dockerfile
346
-
FROM mcr.microsoft.com/dotnet/aspnet:8.0
347
-
WORKDIR /App
348
-
COPY --from=build /App/out .
349
-
ENTRYPOINT ["dotnet", "DotNet.Docker.dll"]
350
-
```
351
-
352
-
:::zone-end
353
-
354
248
The `FROM` command specifies the base image and tag to use. The `WORKDIR` command changes the **current directory** inside of the container to _App_.
355
249
356
250
The `COPY` command tells Docker to copy the specified source directory to a destination folder. In this example, the _publish_ contents in the `build` layer are output into the folder named _App/out_, so it's the source to copy from. All of the published contents in the _App/out_ directory are copied into current working directory (_App_).
@@ -580,6 +474,15 @@ During this tutorial, you created containers and images. If you want, delete the
580
474
581
475
Next, delete any images that you no longer want on your machine. Delete the image created by your _Dockerfile_ and then delete the .NET image the _Dockerfile_ was based on. You can use the **IMAGE ID** or the **REPOSITORY:TAG** formatted string.
0 commit comments