Docker compose an ASP NET Core application with SQL Server
August 29, 2020 by Anuraj
AspNetCore Docker
This blog post is about containerizing an ASP.NET Core Application with SQL Server. In this blog post I will explain how to run the migrations as part of the deployment process.
In this post I am building an ASP.NET Core Web API application and I have enabled Swagger for testing purposes. I have added a Dockerfile
and docker-compose.yaml
file using Visual Studio code.
Here is the Dockerfile
I generated using Docker extension VS Code.
And here is the docker-compose.yml
For running migrations we need to add the package reference of Microsoft.EntityFrameworkCore.Design
. And for the migrations I have created a Dockerfile like this - Migrations.Dockerfile
The Setup.sh
file contains code like this.
In this Dockerfile I am installing the dotnet ef
command. Next I am creating migrations and running the migrations in a loop - this is because the SQL Server will take some time to up and running.
And here is the updated docker-compose.yaml
file.
Now we have completed the setup. So first you need to build the services using the command docker-compose build
and once it is completed, you need to run the docker-compose up
command to run the services. It might take some time to build and run the docker containers. Once the database migration is completed, you will be able to access it from the URL http://localhost:14331, since I have configured the Swagger it will display the Swagger UI like this.
In the docker-compose.yaml
file I have modified SQL Server port and webserver ports, because I am using SQL Server and IIS in my local development machine.
Happy Programming :)
Copyright © 2024 Anuraj. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Powered by Jekyll. Hosted with ❤ by GitHub