2020-03-06 18:25:16 +00:00
## Compose sample application: ASP.NET with MS SQL server database
2020-03-06 16:39:55 +00:00
Project structure:
```
.
├── app
│ ├── aspnetapp
│ │ ├── appsettings.Development.json
| | └── ...
│ ├── ...
│ └── Dockerfile
2022-05-10 09:59:25 +00:00
└── compose.yaml
2020-03-06 16:39:55 +00:00
```
2022-05-10 09:59:25 +00:00
[_compose.yaml_ ](compose.yaml )
2020-03-06 16:39:55 +00:00
```
services:
web:
build: app
ports:
- 80:80
2020-03-06 18:25:16 +00:00
db:
2021-11-08 10:41:35 +00:00
# mssql server image isn't available for arm64 architecture, so we use azure-sql instead
image: mcr.microsoft.com/azure-sql-edge:1.0.4
# If you really want to use MS SQL Server, uncomment the following line
#image: mcr.microsoft.com/mssql/server
2020-03-06 16:39:55 +00:00
...
```
2020-03-06 18:25:16 +00:00
The compose file defines an application with two services `web` and `db` . The image for the web service is built with the Dockerfile inside the `app` directory (build parameter).
2020-03-06 16:39:55 +00:00
2022-05-10 09:59:25 +00:00
When deploying the application, docker compose maps the container port 80 to port 80 of the host as specified in the file.
2020-03-06 16:39:55 +00:00
Make sure port 80 on the host is not being used by another container, otherwise the port should be changed.
2021-11-08 10:41:35 +00:00
> ℹ ️ **_INFO_**
> For compatibility purpose between `AMD64` and `ARM64` architecture, we use Azure SQL Edge as database instead of MS SQL Server.
> You still can use the MS SQL Server image by uncommenting the following line in the Compose file
> `#image: mcr.microsoft.com/mssql/server`
2020-03-06 16:39:55 +00:00
2022-05-10 09:59:25 +00:00
## Deploy with docker compose
2020-03-06 16:39:55 +00:00
```
2022-05-10 09:59:25 +00:00
$ docker compose up -d
2020-03-06 16:39:55 +00:00
Creating network "aspnet-mssql_default" with the default driver
Building web
2021-05-21 16:43:15 +00:00
Step 1/13 : FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
2020-03-06 16:39:55 +00:00
2.1: Pulling from dotnet/core/sdk
....
....
a9dca2f6722a: Pull complete
Digest: sha256:9b700672670bb3db4b212e8aef841ca79eb2fce7d5975a5ce35b7129a9b90ec0
Status: Downloaded newer image for microsoft/mssql-server-linux:latest
Creating aspnet-mssql_web_1 ... done
Creating aspnet-mssql_db_1 ... done
```
## Expected result
Listing containers must show two containers running and the port mapping as below:
```
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7f3a2a7ea5c0 microsoft/mssql-server-linux "/opt/mssql/bin/sqls…" 4 minutes ago Up 4 minutes 1433/tcp aspnet-mssql_db_1
27342dde8b64 aspnet-mssql_web "dotnet aspnetapp.dll" 4 minutes ago Up 4 minutes 0.0.0.0:80->80/tcp aspnet-mssql_web_1
```
After the application starts, navigate to `http://localhost:80` in your web browser.
2020-03-06 18:25:16 +00:00
![page ](output.jpg )
2020-03-06 16:39:55 +00:00
2020-03-06 18:25:16 +00:00
Stop and remove the containers
2020-03-06 16:39:55 +00:00
```
2022-05-10 09:59:25 +00:00
$ docker compose down
2020-03-06 16:39:55 +00:00
```