Example ASP.NET Core project with PostgresQL database demonstrating deployment to VPS using docker and docker-compose.
- Clone the repo to your development machine
- Make necessary changes to
docker-compose-dev.yml,docker-compose-prod.ymland.envfiles - Setup development environment:
docker-compose -f docker-compose-dev.yml --env-file .env up -d --build - Create EntityFramework migrations:
dotnet ef migrations add <MigrationName> - Generate sql file for the migration:
dotnet ef migrations script -s ./WebApp -p ./Infrastructure -o ./DbScripts/migration.sql - Commit & push
- Clone the repo to your server
cdinto the project then:source .env- Build and deploy the containers:
docker-compose --env-file .env up -d --build - Access the todo_postgres container:
docker exec -it todo_postgres /bin/bash - Apply the database migration script:
psql -U "<your_db_username>" -d "<your_db_name>" -a -f scripts/migration.sqlor directly by:docker exec -it todo_postgres psql -U "${DB_USERNAME}" -d "${DB_DATABASE}" -a -f scripts/migration.sql - Setup a reverse proxy in front of your services