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
{{ message }}
This repository was archived by the owner on Jul 18, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: windows/windows-containers/MultiContainerApp.md
+23-36Lines changed: 23 additions & 36 deletions
Original file line number
Diff line number
Diff line change
@@ -2,16 +2,16 @@
2
2
3
3
This tutorial walks you through building and running the sample Album Viewer application with Windows containers. The [Album Viewer](https://github.com/RickStrahl/AlbumViewerVNext) app is an ASP.NET Core application, maintained by Microsoft MVP [Rick Strahl](https://weblog.west-wind.com). There is a fork at [dockersamples/dotnet-album-viewer](https://github.com/dockersamples/dotnet-album-viewer"link to forked version of Album Viewer") which uses Docker Windows containers.
4
4
5
-
> Docker isn't just for new apps built with .NET Core. You can run full .NET Framework apps in Docker Windows containers, with production support in [Docker EE](https://www.docker.com/enterprise-edition). Check out the labs for [Modernizing .NET apps with Docker](https://github.com/docker/labs/tree/master/windows/modernize-traditional-apps).
5
+
> Docker isn't just for new apps built with .NET Core. You can run full .NET Framework apps in Docker Windows containers, with production support in [Docker Enterprise](https://www.docker.com/enterprise-edition). Check out the labs for [Modernizing .NET apps with Docker](https://github.com/docker/labs/tree/master/windows/modernize-traditional-apps).
6
6
7
7
## Using Docker Compose on Windows
8
8
9
9
[Docker Compose](https://docs.docker.com/compose/) is a great way develop distributed applications, where all the components run in their own containers. In this lab you'll use Docker Compose to run SQL Server in a container, as the data store for an ASP.NET Core web application running in another container.
10
10
11
-
Docker Compose is installed with [Docker for Windows](https://www.docker.com/docker-windows). If you've installed Docker as a Windows Service instead, you can download the compose command line using PowerShell:
11
+
Docker Compose is installed with [Docker Desktop on Windows 10](https://www.docker.com/docker-windows). If you've installed the Docker Engine as a Windows Service instead, you can download the compose command line using PowerShell:
To run the sample application in multiple Docker Windows containers, start by cloning the GithUb [dockersamples/dotnet-album-viewer](https://github.com/dockersamples/dotnet-album-viewer/) repository:
@@ -27,41 +27,32 @@ cd dotnet-album-viewer
27
27
docker-compose build
28
28
```
29
29
30
-
You'll see a lot of output here. Docker will pull the .NET Core images if you don't already have them, then it will run `dotnet restore` and `dotnet build` inside a container. You will see the usual NuGet and MSBuild output, even if you don't have the SDK installed.
30
+
You'll see a lot of output here. Docker will pull the .NET Core images if you don't already have them, then it will run `dotnet restore` and `dotnet build` inside a container. You will see the usual NuGet and MSBuild output - you don't need to have the .NET Core SDK installed, because it is part of the Docker image.
31
31
32
32
When the build completes, run the app with:
33
33
34
34
```
35
35
docker-compose up -d
36
36
```
37
37
38
-
Docker starts a database container using Microsoft's [SQL Server Express Windows image](https://store.docker.com/images/mssql-server-windows-express), and when the database is running it starts the application container. The database and application containers are in the same Docker network, so they can reach each other.
38
+
Docker starts a database container using [TiDB](https://github.com/pingcap/tidb), which is a modern distributed database system compatible with MySQL. When the database is running it starts the application container. The database and application containers are in the same Docker network, so they can reach each other.
39
39
40
-
The container for the web application maps to port 80 on the host, so from a different machine you can browse to your host address and see the site:
40
+
The container for the web application publishes port 80 on the host, so you can browse to your http://localhost and see the site:
41
41
42
42

43
43
44
-
If you're working on the host, you need to browse to the container's IP address. You can find it with `docker container inspect`:
### Organizing Distributed Solutions with Docker Compose
52
46
53
-
Take a closer look at the [docker-compose.yml](https://github.com/dockersamples/dotnet-album-viewer/blob/master/docker-compose.yml) file. There are two [services](https://docs.docker.com/compose/compose-file/#service-configuration-reference) defined, which are the different components of the app that will run in Docker containers. The first is the SQL Server database:
47
+
Take a closer look at the [docker-compose.yml](https://github.com/dockersamples/dotnet-album-viewer/blob/master/docker-compose.yml) file. There are two [services](https://docs.docker.com/compose/compose-file/#service-configuration-reference) defined, which are the different components of the app that will run in Docker containers. The first is the MySQL-compatible database:
54
48
55
49
```
56
50
db:
57
-
image: microsoft/mssql-server-windows-express
58
-
environment:
59
-
sa_password: "DockerCon!!!"
60
-
ACCEPT_EULA: "Y"
51
+
image: dockersamples/tidb:nanoserver-1809
52
+
ports:
53
+
- "3306:4000"
61
54
```
62
55
63
-
This uses Microsoft SQL Server Express, which runs as a Docker Windows container. Express edition has a production licence, so you can use it for live applications. The environment settings configure the database, setting the password for the `sa` user account, and accepting the licence agreement.
64
-
65
56
The second service is the ASP.NET Core web application, which uses the custom image you built at the start of the lab:
66
57
67
58
```
@@ -70,42 +61,40 @@ The second service is the ASP.NET Core web application, which uses the custom im
The [build](https://docs.docker.com/compose/compose-file/#build) details capture the path to the Dockerfile. The environment variables are used to configure the app - they override the settings in [appsettings.json](https://github.com/dockersamples/dotnet-album-viewer/blob/master/src/AlbumViewerNetCore/appsettings.json). This configuration uses SQL Server rather than the default SQLite database, and sets the connection string to use the SQL Server container.
73
+
The [build](https://docs.docker.com/compose/compose-file/#build) details capture the path to the Dockerfile. The environment variables are used to configure the app - they override the settings in [appsettings.json](https://github.com/dockersamples/dotnet-album-viewer/blob/master/src/AlbumViewerNetCore/appsettings.json). This configuration uses MySQL rather than the default SQLite database, and sets the connection string to use the TiDB database container.
83
74
84
-
> In the database connection string, the server name is `db` - which is the name of the service for the SQL container. Docker has service discovery built-in, so when the app tries to connect using the server name `db`, Docker will direct it to the database container.
75
+
> The database containerhas a built-in user called `root` with no password, and this is the account used by the web application in the connection string.
85
76
86
77
The app definition also captures the [dependency](https://docs.docker.com/compose/compose-file/#depends_on) on the database server, and publishes port 80 so any traffic coming into the host gets directed by Docker into the container.
87
78
88
-
89
79
## Packaging ASP.NET Core apps in Docker
90
80
91
-
How can you compile and run this app without .NET Core installed? Docker compiles and runs the app using containers. The tasks are in the [Dockerfile](https://github.com/dockersamples/dotnet-album-viewer/blob/master/docker/app/Dockerfile), which captures all the app dependencies so the only pre-requisite you need is Docker. The first stage in the Dockerfile publishes the app:
81
+
How can you compile and run this app without .NET Core installed? Docker compiles and runs the app using containers. The tasks are in the [Dockerfile](https://github.com/dockersamples/dotnet-album-viewer/blob/master/docker/app/Dockerfile), which captures the app dependencies so the only pre-requisite you need is Docker. The first stage in the Dockerfile publishes the app:
92
82
93
83
```
94
-
FROM microsoft/dotnet:2.0.0-sdk-nanoserver AS builder
RUN dotnet restore src/AlbumViewerNetCore/AlbumViewerNetCore.csproj
103
92
104
93
COPY src src
105
94
RUN dotnet publish .\src\AlbumViewerNetCore\AlbumViewerNetCore.csproj
106
95
```
107
96
108
-
This uses Microsoft's [.NET Core Docker image](https://store.docker.com/images/dotnet) as the base in the `FROM` instruction. It uses a specific version of the image, with the .NET Core 2.0.0 SDK installed, running on Microsoft Nano Server. Then the `COPY` instructions copy the project files and solution files into the image, and the `RUN` instruction executes `dotnet restore` to restore packages.
97
+
This uses Microsoft's [.NET Core Docker image](https://hub.docker.com/r/microsoft/dotnet) as the base in the `FROM` instruction. It uses a specific version of the image, with the .NET Core 2.1 SDK installed, running on the 1809 release of Microsoft Nano Server. Then the `COPY` instructions copy the project files and solution files into the image, and the `RUN` instruction executes `dotnet restore` to restore packages.
109
98
110
99
Docker caches parts of the image as it build them, and this Dockerfile separates out the restore part to take advantage of that. Unless the solution or project files change, Docker will re-use the image layer with the dependencies already restored, saving time on the `dotnet restore` operation.
111
100
@@ -115,18 +104,16 @@ The final stage in the Dockerfile packages the published application:
This uses a different base image, which is optimized for running [ASP.NET Core](https://store.docker.com/community/images/microsoft/aspnetcore) apps. It has the .NET Core runtime, but not the SDK, and the ASP.NET core packages are already installed. The `COPY` instruction copies the published .NET Core app from the previous stage in the Dockerfile (called `builder`), and the `CMD` instruction tells Docker how to start the app.
127
-
128
-
The Dockerfile syntax is simple. You only need to learn a handful of instructions to build production-grade Docker images. Inside the Dockerfile, you can use PowerShell to deploy MSIs, update Windows Registry settings, set file permissions and do anything else you need.
114
+
This uses a different variant of the `dotnet` base image, which is optimized for running ASP.NET Core apps. It has the .NET Core runtime, but not the SDK, and the ASP.NET core packages are already installed. The `COPY` instruction copies the published .NET Core app from the previous stage in the Dockerfile (called `builder`), and the `CMD` instruction tells Docker how to start the app.
129
115
116
+
The Dockerfile syntax is simple. You only need to learn a handful of instructions to build production-grade Docker images. Inside the Dockerfile you can use PowerShell to deploy MSIs, update Windows Registry settings, set file permissions and do anything else you need.
In September 2016, Microsoft announced the general availability of Windows Server 2016, and with it, Docker engine running containers natively on Windows. This tutorial describes how to get setup to run Docker Windows Containers on Windows 10 or using a Windows Server 2016 VM.
3
+
Docker containers run natively in Windows Server 2016, Windows Server 2019 and Windows 10. These labs are based on the latest releases of Windows and Docker which provide the best experience for containerized Windows applications.
4
4
5
-
If you are developing locally, you must be running Windows 10 pro or Windows 2016 in a virtual machine to be able to use this tutorial.
5
+
The minimum requirements are:
6
6
7
-
If you're using a cloud VM, you must use Windows 2016 VM.
7
+
* Windows 10 Professional or Enterprise, with Windows update 1809 *or*
8
+
* Windows Server 2019
8
9
10
+
## Step 1 - Setup
9
11
10
-
This tutorial consists of three parts:
12
+
You can run Windows containers on Windows 10, Windows Server 2016 and Windows Server 2019:
11
13
12
-
1.[Setup](Setup.md"Setup"): Making sure your development environment is properly set-up to work with Windows Containers.
13
-
2.[Getting Started with Windows Containers](WindowsContainers.md"Getting Started with Windows Containers"): The basics of Windows Containers.
14
-
3.[Multi-Container Applications](MultiContainerApp.md"Multi-Container Applications"): Using [Docker Compose](https://docker.github.io/compose/"Docker Compose") to launch a website based on Microsoft SQL Server.
14
+
+[Install Docker Desktop on Windows 10](https://hub.docker.com/editions/community/docker-ce-desktop-windows"Windows 10 Setup")
15
+
+[Install Docker Enterprise Engine on Windows Server](https://hub.docker.com/editions/enterprise/docker-ee-server-windows"Setup on Windows Server")
16
+
17
+
> Most public cloud providers also have a VM image with Docker already installed. You can use Microsoft's **Windows Server 2019 Datacenter with Containers** VM image on Azure, and Amazon's **Microsoft Windows Server 2019 Base with Containers** AMI on AWS.
18
+
19
+
## Verification
20
+
21
+
Run `docker version` to check the basic details of your deployment. You should see "Windows" listed as the operating system for the Docker client and the Docker Engine:
22
+
23
+
```
24
+
PS>docker version
25
+
Client: Docker Engine - Community
26
+
Version: 18.09.1
27
+
API version: 1.39
28
+
Go version: go1.10.6
29
+
Git commit: 4c52b90
30
+
Built: Wed Jan 9 19:34:26 2019
31
+
OS/Arch: windows/amd64
32
+
Experimental: false
33
+
34
+
Server: Docker Engine - Community
35
+
Engine:
36
+
Version: 18.09.1
37
+
API version: 1.39 (minimum version 1.24)
38
+
Go version: go1.10.6
39
+
Git commit: 4c52b90
40
+
Built: Wed Jan 9 19:50:10 2019
41
+
OS/Arch: windows/amd64
42
+
Experimental: true
43
+
```
44
+
45
+
> The `OS/Arch` field tells you the operating system and CPU architecture you're using. Docker is cross-platform, so you can manage Windows Docker servers from a Linux client and vice-versa, using the same `docker` commands.
46
+
47
+
## Windows Versions
48
+
49
+
The latest release of Windows to support Docker containers is Windows Server 2019, and Windows 10 with the 1809 update. There are many enhancements from the original Windows containers release in Server 2016.
50
+
51
+
> [Read about the new container features with Docker on Windows Server 2019](https://blog.docker.com/2019/01/announcing-support-for-windows-server-2019-within-docker-enterprise/)
52
+
53
+
Windows containers need to match the version of the OS where the container is running with the version of the OS inside the container. Container images flagged as `ltsc2019` or `1809` work with the latest Windows versions.
54
+
55
+
56
+
## Next Steps
57
+
58
+
Continue to Step 2: [Getting Started with Windows Containers](WindowsContainers.md"Getting Started with Windows Containers")
0 commit comments