Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Build results
**/bin/
**/obj/
**/out/
**/publish/

# Test results
**/*Tests/TestResults/
**/*.trx
**/*.coverage

# User-specific files
**/*.user
**/*.suo
**/*.userosscache
**/.vs/

# Build artifacts
**/.vscode/
**/.idea/
*.sln.DotSettings.user

# Git
.git/
.gitignore
.gitattributes

# Docker
**/.dockerignore
**/Dockerfile*
**/docker-compose*

# Documentation
**/*.md
!README.Docker.md

# NuGet
**/*.nupkg
**/.nuget/

# Misc
**/node_modules/
**/npm-debug.log
**/.DS_Store
**/Thumbs.db
41 changes: 41 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Build stage
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
WORKDIR /src

# Copy solution and project files
COPY src/*.sln ./
COPY src/CSharpApp.Api/*.csproj ./CSharpApp.Api/
COPY src/CSharpApp.Application/*.csproj ./CSharpApp.Application/
COPY src/CSharpApp.Core/*.csproj ./CSharpApp.Core/
COPY src/CSharpApp.Infrastructure/*.csproj ./CSharpApp.Infrastructure/
COPY src/CSharpApp.Models/*.csproj ./CSharpApp.Models/
COPY src/test/CSharpApp.Tests/*.csproj ./test/CSharpApp.Tests/

# Restore dependencies
RUN dotnet restore

# Copy all source code
COPY src/ ./

# Build and publish
RUN dotnet publish CSharpApp.Api/CSharpApp.Api.csproj -c Release -o /app/publish /p:UseAppHost=false

# Runtime stage
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime
WORKDIR /app

# Create non-root user
RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app
USER appuser

# Copy published app
COPY --from=build /app/publish .

# Expose port
EXPOSE 8080

# Set environment variables
ENV ASPNETCORE_URLS=http://+:8080
ENV ASPNETCORE_ENVIRONMENT=Production

ENTRYPOINT ["dotnet", "CSharpApp.Api.dll"]
199 changes: 199 additions & 0 deletions QUICKSTART.Docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
# Docker Quick Start Guide

## 🚀 Getting Started with Docker

All Docker files have been successfully added to your repository!

### 📁 Files Created:

1. **Dockerfile** - Multi-stage build configuration
2. **docker-compose.yml** - Production configuration
3. **docker-compose.override.yml** - Development overrides
4. **.dockerignore** - Build optimization
5. **README.Docker.md** - Complete documentation

---

## ⚡ Quick Commands

### Build and Run
```powershell
# Navigate to repository root
cd C:\Users\Boss\source\repos\novibet

# Build and start the application
docker-compose up --build

# Run in detached mode (background)
docker-compose up -d --build
```

### Access the API
- **API Base URL**: http://localhost:8080
- **Products Endpoint**: http://localhost:8080/api/v1/products
- **Categories Endpoint**: http://localhost:8080/api/v1/categories

### Test the API
```powershell
# Get all products
curl http://localhost:8080/api/v1/products

# Get product by ID
curl http://localhost:8080/api/v1/products/1

# Get all categories
curl http://localhost:8080/api/v1/categories
```

### View Logs
```powershell
# Follow logs in real-time
docker-compose logs -f

# View last 50 lines
docker-compose logs --tail=50
```

### Stop the Application
```powershell
# Stop containers
docker-compose down

# Stop and remove volumes
docker-compose down -v
```

---

## 🔧 Development Mode

For enhanced debugging and logging:

```powershell
docker-compose -f docker-compose.yml -f docker-compose.override.yml up --build
```

This enables:
- ✅ Development environment
- ✅ Debug-level logging
- ✅ Detailed HTTP client logs

---

## 📦 What's Included

### Dockerfile Features:
- ✅ .NET 9 SDK for build stage
- ✅ .NET 9 ASP.NET Core runtime for production
- ✅ Multi-stage build (optimized image size ~100MB)
- ✅ Non-root user for security
- ✅ Port 8080 exposed

### Docker Compose Features:
- ✅ Automatic health checks
- ✅ Environment variable configuration
- ✅ Network isolation
- ✅ Restart policy (unless-stopped)
- ✅ Development overrides

### Security Features:
- ✅ Non-root user (appuser)
- ✅ No build tools in production image
- ✅ Minimal attack surface
- ✅ Environment-based secrets

---

## 🐛 Troubleshooting

### Port 8080 Already in Use
Edit `docker-compose.yml` and change:
```yaml
ports:
- "8081:8080" # Use different host port
```

### View Container Details
```powershell
# List running containers
docker ps

# Inspect container
docker inspect csharpapp-api

# Enter container shell
docker exec -it csharpapp-api /bin/bash
```

### Rebuild from Scratch
```powershell
docker-compose down
docker-compose build --no-cache
docker-compose up
```

---

## 📚 Next Steps

1. **Test the build**: `docker-compose up --build`
2. **Verify endpoints**: Access http://localhost:8080/api/v1/products
3. **Review logs**: `docker-compose logs -f`
4. **Read full docs**: See `README.Docker.md` for complete documentation
5. **Commit changes**: Add Docker files to Git

---

## 🎯 Git Commands

```powershell
# Stage Docker files
git add Dockerfile docker-compose.yml docker-compose.override.yml .dockerignore README.Docker.md QUICKSTART.Docker.md

# Commit changes
git commit -m "feat: add Docker support to solution"

# Push to remote
git push origin feat/-add-docker-support-to-solution
```

---

## 📖 Full Documentation

For detailed information, see **README.Docker.md** which includes:
- Complete configuration options
- Security best practices
- CI/CD integration examples
- Production deployment guide
- Performance tuning tips
- Monitoring and logging setup

---

## ✅ Validation Checklist

Before pushing to production:

- [ ] Docker build completes successfully
- [ ] Application starts and responds to requests
- [ ] Health checks pass
- [ ] Logs show no errors
- [ ] API endpoints return expected responses
- [ ] Environment variables are configured correctly
- [ ] Security scan passes (optional: `docker scan csharpapp-api:latest`)

---

## 🆘 Support

For issues or questions:
1. Check logs: `docker-compose logs -f`
2. Review README.Docker.md troubleshooting section
3. Verify Docker Desktop is running
4. Ensure port 8080 is available
5. Check network connectivity

---

**Happy containerizing! 🐳**
Loading