Project.Fengling.QoderVersion/Backend/scripts/EXAMPLES.md
sam e24925e1ed chore(build): 添加基础构建配置和版本管理
- 新增 .dockerignore 文件,忽略多种临时及中间文件
- 新增 .gitattributes 文件,配置文本文件换行及合并行为
- 新增详细的 .gitignore 文件,排除多种开发及生成文件
- 新增 VS Code C# 代码片段,提升开发效率
- 添加 Directory.Build.props,统一 MSBuild 配置和代码分析规则
- 添加空的 Directory.Build.targets,预留构建任务扩展位置
- 添加 Directory.Packages.props,实现依赖包版本集中管理和声明
2026-02-11 12:58:54 +08:00

3.0 KiB

Usage Examples

This document provides practical examples for using the infrastructure initialization scripts.

Quick Start Examples

Default Setup (MySQL + Redis + RabbitMQ)

# Using Docker Compose (Recommended)
docker compose up -d

# Using shell script (Linux/macOS)
./init-infrastructure.sh

# Using PowerShell (Windows)
.\init-infrastructure.ps1

Different Database Options

# Use PostgreSQL instead of MySQL
docker compose --profile postgres up -d

# Use SQL Server instead of MySQL  
docker compose --profile sqlserver up -d

# With PowerShell
.\init-infrastructure.ps1 -Postgres
.\init-infrastructure.ps1 -SqlServer

Different Message Queue Options

# Use Kafka instead of RabbitMQ
docker compose --profile kafka up -d

# With PowerShell
.\init-infrastructure.ps1 -Kafka

Cleanup Examples

# Stop services, keep data
docker compose down
./clean-infrastructure.sh
.\clean-infrastructure.ps1

# Stop services and remove all data
docker compose down -v
./clean-infrastructure.sh --volumes  
.\clean-infrastructure.ps1 -Volumes

Development Workflow

Typical Development Session

# 1. Start infrastructure
cd scripts
docker compose up -d

# 2. Develop your application
cd ../src/Fengling.Backend.Web
dotnet run

# 3. Run tests
cd ../../
dotnet test

# 4. Stop infrastructure (keep data)
cd scripts
docker compose down

Clean Development Environment

# Clean slate - remove everything including data
cd scripts  
docker compose down -v

# Start fresh
docker compose up -d

Troubleshooting

Check Service Status

# List running containers
docker ps

# Check specific service logs
docker logs netcorepal-mysql
docker logs netcorepal-redis
docker logs netcorepal-rabbitmq

# Check service health
docker compose ps

Common Issues

Port Already in Use

# Find what's using the port
netstat -tulpn | grep :3306  # Linux
netstat -ano | findstr :3306  # Windows

# Stop conflicting services
sudo systemctl stop mysql  # Linux
net stop mysql80           # Windows

Container Won't Start

# Remove problematic container and restart
docker rm -f netcorepal-mysql
docker compose up -d mysql

Data Corruption

# Remove data volumes and start fresh
docker compose down -v
docker compose up -d

Connection Strings for Development

Update your appsettings.Development.json with these connection strings:

{
  "ConnectionStrings": {
    "Redis": "localhost:6379,defaultDatabase=0",
    "MySql": "Server=localhost;Port=3306;Database=abctemplate;Uid=root;Pwd=123456;",
    "SqlServer": "Server=localhost,1433;Database=abctemplate;User Id=sa;Password=Test123456!;TrustServerCertificate=true;",
    "PostgreSQL": "Host=localhost;Port=5432;Database=abctemplate;Username=postgres;Password=123456;"
  },
  "RabbitMQ": {
    "HostName": "localhost",
    "Port": 5672,
    "UserName": "guest",
    "Password": "guest",
    "VirtualHost": "/"
  },
  "Kafka": {
    "BootstrapServers": "localhost:9092"
  }
}