A simple .NET Web API connected to a SQL Server instance using Entity Framework Core, all running inside Docker containers.
-
Start the containers:
docker-compose up -d
-
Stop and remove containers:
docker-compose down
-
Rebuild the image (if changes are made):
docker-compose up --build -d
-
Access the API:
- Main endpoint: http://localhost:2502
- Get all products: http://localhost:2502/api/products
When the API starts, it checks if the database has data. If empty, it inserts:
[
{ "name": "Laptop", "price": 50000 },
{ "name": "Mouse", "price": 800 }
]Dockerized-DotNetAPI-WithSql/
├── Dockerfile
├── docker-compose.yml
├── Dockerized-DotNetAPI-SqlServer.csproj
├── Program.cs
├── Data/
│ └── AppDbContext.cs
└── Models/
└── Product.cs
- 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
- 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.