Skip to content

About

This repository demonstrates how to build and run a simple .NET Core Web API with a SQL Server database inside Docker containers. It showcases the use of Docker Compose for managing multi-container applications, including persistent storage for the database. The API allows basic CRUD operations on a Products table using Entity Framework Core.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

🚀 Dockerized DotNet API with SQL Server

A simple .NET Web API connected to a SQL Server instance using Entity Framework Core, all running inside Docker containers.


🐳 How to Run (Using Docker Compose)

  1. Start the containers:

    docker-compose up -d
  2. Stop and remove containers:

    docker-compose down
  3. Rebuild the image (if changes are made):

    docker-compose up --build -d
  4. Access the API:


🧪 Seeded Sample Data

When the API starts, it checks if the database has data. If empty, it inserts:

[
  { "name": "Laptop", "price": 50000 },
  { "name": "Mouse", "price": 800 }
]

💠 Project Structure

Dockerized-DotNetAPI-WithSql/
├── Dockerfile
├── docker-compose.yml
├── Dockerized-DotNetAPI-SqlServer.csproj
├── Program.cs
├── Data/
│   └── AppDbContext.cs
└── Models/
    └── Product.cs

💾 Database

  • Uses SQL Server 2022 in Docker.
  • Persists data via named Docker volume sqlserver_data.

You can connect to the SQL Server via SSMS using:

Server: localhost,1433  
User: sa  
Password: YourStrong!Passw0rd

📌 Notes

  • API is exposed on http://localhost:2502.
  • Database is seeded at runtime if no data exists.
  • Make sure Docker is installed and running.
  • Based on ASP.NET Core 9 and EF Core 9.

About

This repository demonstrates how to build and run a simple .NET Core Web API with a SQL Server database inside Docker containers. It showcases the use of Docker Compose for managing multi-container applications, including persistent storage for the database. The API allows basic CRUD operations on a Products table using Entity Framework Core.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages