Skip to content

Commit a279f7f

Browse files
Ra/docker/versions (#35104)
* Update to .NET 9.0 * update docker to .NET 9 * update docker to .NET 9 * update docker to .NET 9 --------- Co-authored-by: AppleSilicon <70263679+AppleSilicon@users.noreply.github.com>
1 parent ff4917e commit a279f7f

File tree

3 files changed

+344
-172
lines changed

3 files changed

+344
-172
lines changed

aspnetcore/host-and-deploy/docker/building-net-docker-images.md

Lines changed: 2 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -18,177 +18,7 @@ Windows Home Edition doesn't support Hyper-V, and Hyper-V is needed for Docker.
1818

1919
See [Containerize a .NET app with dotnet publish](/dotnet/core/docker/publish-as-container) for information on containerized a .NET app with `dotnet publish`.
2020

21-
:::moniker range=">= aspnetcore-8.0"
22-
23-
## ASP.NET Core Docker images
24-
25-
For this tutorial, you download an ASP.NET Core sample app and run it in Docker containers. The sample works with both Linux and Windows containers.
26-
27-
The sample Dockerfile uses the [Docker multi-stage build feature](https://docs.docker.com/engine/userguide/eng-image/multistage-build/) to build and run in different containers. The build and run containers are created from images that are provided in Docker Hub by Microsoft:
28-
29-
* `dotnet/sdk`
30-
31-
The sample uses this image for building the app. The image contains the .NET SDK, which includes the Command Line Tools (CLI). The image is optimized for local development, debugging, and unit testing. The tools installed for development and compilation make the image relatively large.
32-
33-
* `dotnet/aspnet`
34-
35-
The sample uses this image for running the app. The image contains the ASP.NET Core runtime and libraries and is optimized for running apps in production. Designed for speed of deployment and app startup, the image is relatively small, so network performance from Docker Registry to Docker host is optimized. Only the binaries and content needed to run an app are copied to the container. The contents are ready to run, enabling the fastest time from `docker run` to app startup. Dynamic code compilation isn't needed in the Docker model.
36-
37-
## Prerequisites
38-
39-
* [.NET SDK 8.0](https://dotnet.microsoft.com/download)
40-
* Docker client 18.03 or later
41-
42-
* Linux distributions
43-
* [Debian](https://docs.docker.com/install/linux/docker-ce/debian/)
44-
* [Fedora](https://docs.docker.com/install/linux/docker-ce/fedora/)
45-
* [Ubuntu](https://docs.docker.com/install/linux/docker-ce/ubuntu/)
46-
* [macOS](https://docs.docker.com/desktop/mac/install/)
47-
* [Windows](https://docs.docker.com/desktop/windows/install/)
48-
49-
* [Git](https://git-scm.com/download)
50-
51-
## Download the sample app
52-
53-
* Download the sample by cloning the [.NET Docker repository](https://github.com/dotnet/dotnet-docker):
54-
55-
```console
56-
git clone https://github.com/dotnet/dotnet-docker
57-
```
58-
59-
## Run the app locally
60-
61-
* Navigate to the project folder at *dotnet-docker/samples/aspnetapp/aspnetapp*.
62-
63-
* Run the following command to build and run the app locally:
64-
65-
```dotnetcli
66-
dotnet run
67-
```
68-
69-
* Go to `http://localhost:<port>` in a browser to test the app.
70-
71-
* Press Ctrl+C at the command prompt to stop the app.
72-
73-
## Run in a Linux container or Windows container
74-
75-
* To run in a Linux container, right-click the System Tray's Docker client icon and select [switch to Linux containers](https://docs.docker.com/desktop/windows/#switch-between-windows-and-linux-containers).
76-
* To run in a Windows container, right-click the System Tray's Docker client icon and select [switch to Windows containers](https://docs.docker.com/desktop/windows/#switch-between-windows-and-linux-containers).
77-
78-
* Navigate to the Dockerfile folder at *dotnet-docker/samples/aspnetapp*.
79-
80-
* Run the following commands to build and run the sample in Docker:
81-
82-
```console
83-
docker build -t aspnetapp .
84-
docker run -it --rm -p <port>:8080 --name aspnetcore_sample aspnetapp
85-
```
86-
87-
The `build` command arguments:
88-
* Name the image aspnetapp.
89-
* Look for the Dockerfile in the current folder (the period at the end).
90-
91-
The run command arguments:
92-
* Allocate a pseudo-TTY and keep it open even if not attached. (Same effect as `--interactive --tty`.)
93-
* Automatically remove the container when it exits.
94-
* Map `<port>` on the local machine to port 8080 in the container.
95-
* Name the container aspnetcore_sample.
96-
* Specify the aspnetapp image.
97-
98-
* Go to `http://localhost:<port>` in a browser to test the app.
99-
100-
## Build and deploy manually
101-
102-
In some scenarios, you might want to deploy an app to a container by copying its assets that are needed at run time. This section shows how to deploy manually.
103-
104-
* Navigate to the project folder at *dotnet-docker/samples/aspnetapp/aspnetapp*.
105-
106-
* Run the [dotnet publish](/dotnet/core/tools/dotnet-publish) command:
107-
108-
```dotnetcli
109-
dotnet publish -c Release -o published
110-
```
111-
112-
The command arguments:
113-
* Build the app in release mode (the default is debug mode).
114-
* Create the assets in the *published* folder.
115-
116-
* Run the app.
117-
118-
* Windows:
119-
120-
```dotnetcli
121-
dotnet published\aspnetapp.dll
122-
```
123-
124-
* Linux:
125-
126-
```dotnetcli
127-
dotnet published/aspnetapp.dll
128-
```
129-
130-
* Browse to `http://localhost:<port>` to see the home page.
131-
132-
To use the manually published app within a Docker container, create a new *Dockerfile* and use the `docker build .` command to build an image.
133-
134-
```dockerfile
135-
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
136-
WORKDIR /app
137-
COPY published/ ./
138-
ENTRYPOINT ["dotnet", "aspnetapp.dll"]
139-
```
140-
141-
To see the new image use the `docker images` command.
142-
143-
### The Dockerfile
144-
145-
Here's the *Dockerfile* used by the `docker build` command you ran earlier. It uses `dotnet publish` the same way you did in this section to build and deploy.
146-
147-
```dockerfile
148-
# https://hub.docker.com/_/microsoft-dotnet
149-
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
150-
WORKDIR /source
151-
152-
# copy csproj and restore as distinct layers
153-
COPY *.sln .
154-
COPY aspnetapp/*.csproj ./aspnetapp/
155-
RUN dotnet restore
156-
157-
# copy everything else and build app
158-
COPY aspnetapp/. ./aspnetapp/
159-
WORKDIR /source/aspnetapp
160-
RUN dotnet publish -c release -o /app --no-restore
161-
162-
# final stage/image
163-
FROM mcr.microsoft.com/dotnet/aspnet:8.0
164-
WORKDIR /app
165-
COPY --from=build /app ./
166-
ENTRYPOINT ["dotnet", "aspnetapp.dll"]
167-
```
168-
169-
In the preceding *Dockerfile*, the `*.csproj` files are copied and restored as distinct *layers*. When the `docker build` command builds an image, it uses a built-in cache. If the `*.csproj` files haven't changed since the `docker build` command last ran, the `dotnet restore` command doesn't need to run again. Instead, the built-in cache for the corresponding `dotnet restore` layer is reused. For more information, see [Best practices for writing Dockerfiles](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#leverage-build-cache).
170-
171-
## Additional resources
172-
173-
* [Containerize a .NET app with dotnet publish](/dotnet/core/docker/publish-as-container)
174-
* [Docker build command](https://docs.docker.com/engine/reference/commandline/build)
175-
* [Docker run command](https://docs.docker.com/engine/reference/commandline/run)
176-
* [ASP.NET Core Docker sample](https://github.com/dotnet/dotnet-docker) (The one used in this tutorial.)
177-
* [Configure ASP.NET Core to work with proxy servers and load balancers](xref:host-and-deploy/proxy-load-balancer)
178-
* [Working with Visual Studio Docker Tools](xref:host-and-deploy/docker/visual-studio-tools-for-docker)
179-
* [Debugging with Visual Studio Code](https://code.visualstudio.com/docs/nodejs/debugging-recipes#_debug-nodejs-in-docker-containers)
180-
* [GC using Docker and small containers](xref:performance/memory#sc)
181-
* [System.IO.IOException: The configured user limit (128) on the number of inotify instances has been reached](xref:host-and-deploy/docker/index#d128)
182-
* [Updates to Docker images](https://andrewlock.net/exploring-the-dotnet-8-preview-updates-to-docker-images-in-dotnet-8/)
183-
184-
## Next steps
185-
186-
The Git repository that contains the sample app also includes documentation. For an overview of the resources available in the repository, see [the README file](https://github.com/dotnet/dotnet-docker/blob/main/samples/aspnetapp/README.md). In particular, learn how to implement HTTPS:
187-
188-
> [!div class="nextstepaction"]
189-
> [Developing ASP.NET Core Applications with Docker over HTTPS](https://github.com/dotnet/dotnet-docker/blob/main/samples/run-aspnetcore-https-development.md)
190-
191-
:::moniker-end
192-
21+
[!INCLUDE[](~/host-and-deploy/docker/includes/building-net-docker-images9.md)]
22+
[!INCLUDE[](~/host-and-deploy/docker/includes/building-net-docker-images8.md)]
19323
[!INCLUDE[](~/host-and-deploy/docker/includes/building-net-docker-images7.md)]
19424
[!INCLUDE[](~/host-and-deploy/docker/includes/building-net-docker-images5.md)]
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
:::moniker range="= aspnetcore-8.0"
2+
3+
## ASP.NET Core Docker images
4+
5+
For this tutorial, you download an ASP.NET Core sample app and run it in Docker containers. The sample works with both Linux and Windows containers.
6+
7+
The sample Dockerfile uses the [Docker multi-stage build feature](https://docs.docker.com/engine/userguide/eng-image/multistage-build/) to build and run in different containers. The build and run containers are created from images that are provided in Docker Hub by Microsoft:
8+
9+
* `dotnet/sdk`
10+
11+
The sample uses this image for building the app. The image contains the .NET SDK, which includes the Command Line Tools (CLI). The image is optimized for local development, debugging, and unit testing. The tools installed for development and compilation make the image relatively large.
12+
13+
* `dotnet/aspnet`
14+
15+
The sample uses this image for running the app. The image contains the ASP.NET Core runtime and libraries and is optimized for running apps in production. Designed for speed of deployment and app startup, the image is relatively small, so network performance from Docker Registry to Docker host is optimized. Only the binaries and content needed to run an app are copied to the container. The contents are ready to run, enabling the fastest time from `docker run` to app startup. Dynamic code compilation isn't needed in the Docker model.
16+
17+
## Prerequisites
18+
19+
* [.NET SDK 8.0](https://dotnet.microsoft.com/download)
20+
* Docker client 18.03 or later
21+
22+
* Linux distributions
23+
* [Debian](https://docs.docker.com/install/linux/docker-ce/debian/)
24+
* [Fedora](https://docs.docker.com/install/linux/docker-ce/fedora/)
25+
* [Ubuntu](https://docs.docker.com/install/linux/docker-ce/ubuntu/)
26+
* [macOS](https://docs.docker.com/desktop/mac/install/)
27+
* [Windows](https://docs.docker.com/desktop/windows/install/)
28+
29+
* [Git](https://git-scm.com/download)
30+
31+
## Download the sample app
32+
33+
* Download the sample by cloning the [.NET Docker repository](https://github.com/dotnet/dotnet-docker):
34+
35+
```console
36+
git clone https://github.com/dotnet/dotnet-docker
37+
```
38+
39+
## Run the app locally
40+
41+
* Navigate to the project folder at *dotnet-docker/samples/aspnetapp/aspnetapp*.
42+
43+
* Run the following command to build and run the app locally:
44+
45+
```dotnetcli
46+
dotnet run
47+
```
48+
49+
* Go to `http://localhost:<port>` in a browser to test the app.
50+
51+
* Press Ctrl+C at the command prompt to stop the app.
52+
53+
## Run in a Linux container or Windows container
54+
55+
* To run in a Linux container, right-click the System Tray's Docker client icon and select [switch to Linux containers](https://docs.docker.com/desktop/windows/#switch-between-windows-and-linux-containers).
56+
* To run in a Windows container, right-click the System Tray's Docker client icon and select [switch to Windows containers](https://docs.docker.com/desktop/windows/#switch-between-windows-and-linux-containers).
57+
58+
* Navigate to the Dockerfile folder at *dotnet-docker/samples/aspnetapp*.
59+
60+
* Run the following commands to build and run the sample in Docker:
61+
62+
```console
63+
docker build -t aspnetapp .
64+
docker run -it --rm -p <port>:8080 --name aspnetcore_sample aspnetapp
65+
```
66+
67+
The `build` command arguments:
68+
* Name the image aspnetapp.
69+
* Look for the Dockerfile in the current folder (the period at the end).
70+
71+
The run command arguments:
72+
* Allocate a pseudo-TTY and keep it open even if not attached. (Same effect as `--interactive --tty`.)
73+
* Automatically remove the container when it exits.
74+
* Map `<port>` on the local machine to port 8080 in the container.
75+
* Name the container aspnetcore_sample.
76+
* Specify the aspnetapp image.
77+
78+
* Go to `http://localhost:<port>` in a browser to test the app.
79+
80+
## Build and deploy manually
81+
82+
In some scenarios, you might want to deploy an app to a container by copying its assets that are needed at run time. This section shows how to deploy manually.
83+
84+
* Navigate to the project folder at *dotnet-docker/samples/aspnetapp/aspnetapp*.
85+
86+
* Run the [dotnet publish](/dotnet/core/tools/dotnet-publish) command:
87+
88+
```dotnetcli
89+
dotnet publish -c Release -o published
90+
```
91+
92+
The command arguments:
93+
* Build the app in release mode (the default is debug mode).
94+
* Create the assets in the *published* folder.
95+
96+
* Run the app.
97+
98+
* Windows:
99+
100+
```dotnetcli
101+
dotnet published\aspnetapp.dll
102+
```
103+
104+
* Linux:
105+
106+
```dotnetcli
107+
dotnet published/aspnetapp.dll
108+
```
109+
110+
* Browse to `http://localhost:<port>` to see the home page.
111+
112+
To use the manually published app within a Docker container, create a new *Dockerfile* and use the `docker build .` command to build an image.
113+
114+
```dockerfile
115+
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
116+
WORKDIR /app
117+
COPY published/ ./
118+
ENTRYPOINT ["dotnet", "aspnetapp.dll"]
119+
```
120+
121+
To see the new image use the `docker images` command.
122+
123+
### The Dockerfile
124+
125+
Here's the *Dockerfile* used by the `docker build` command you ran earlier. It uses `dotnet publish` the same way you did in this section to build and deploy.
126+
127+
```dockerfile
128+
# https://hub.docker.com/_/microsoft-dotnet
129+
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
130+
WORKDIR /source
131+
132+
# copy csproj and restore as distinct layers
133+
COPY *.sln .
134+
COPY aspnetapp/*.csproj ./aspnetapp/
135+
RUN dotnet restore
136+
137+
# copy everything else and build app
138+
COPY aspnetapp/. ./aspnetapp/
139+
WORKDIR /source/aspnetapp
140+
RUN dotnet publish -c release -o /app --no-restore
141+
142+
# final stage/image
143+
FROM mcr.microsoft.com/dotnet/aspnet:8.0
144+
WORKDIR /app
145+
COPY --from=build /app ./
146+
ENTRYPOINT ["dotnet", "aspnetapp.dll"]
147+
```
148+
149+
In the preceding *Dockerfile*, the `*.csproj` files are copied and restored as distinct *layers*. When the `docker build` command builds an image, it uses a built-in cache. If the `*.csproj` files haven't changed since the `docker build` command last ran, the `dotnet restore` command doesn't need to run again. Instead, the built-in cache for the corresponding `dotnet restore` layer is reused. For more information, see [Best practices for writing Dockerfiles](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#leverage-build-cache).
150+
151+
## Additional resources
152+
153+
* [Containerize a .NET app with dotnet publish](/dotnet/core/docker/publish-as-container)
154+
* [Docker build command](https://docs.docker.com/engine/reference/commandline/build)
155+
* [Docker run command](https://docs.docker.com/engine/reference/commandline/run)
156+
* [ASP.NET Core Docker sample](https://github.com/dotnet/dotnet-docker) (The one used in this tutorial.)
157+
* [Configure ASP.NET Core to work with proxy servers and load balancers](xref:host-and-deploy/proxy-load-balancer)
158+
* [Working with Visual Studio Docker Tools](xref:host-and-deploy/docker/visual-studio-tools-for-docker)
159+
* [Debugging with Visual Studio Code](https://code.visualstudio.com/docs/nodejs/debugging-recipes#_debug-nodejs-in-docker-containers)
160+
* [GC using Docker and small containers](xref:performance/memory#sc)
161+
* [System.IO.IOException: The configured user limit (128) on the number of inotify instances has been reached](xref:host-and-deploy/docker/index#d128)
162+
* [Updates to Docker images](https://andrewlock.net/exploring-the-dotnet-8-preview-updates-to-docker-images-in-dotnet-8/)
163+
164+
## Next steps
165+
166+
The Git repository that contains the sample app also includes documentation. For an overview of the resources available in the repository, see [the README file](https://github.com/dotnet/dotnet-docker/blob/main/samples/aspnetapp/README.md). In particular, learn how to implement HTTPS:
167+
168+
> [!div class="nextstepaction"]
169+
> [Developing ASP.NET Core Applications with Docker over HTTPS](https://github.com/dotnet/dotnet-docker/blob/main/samples/run-aspnetcore-https-development.md)
170+
171+
:::moniker-end

0 commit comments

Comments
 (0)