Docker compose an ASP NET Core application with SQL Server
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
docker-compose.yaml file using Visual Studio code.
Here is the
Dockerfile I generated using Docker extension VS Code.
And here is the
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 -
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
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.
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 :)