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.yml
and.env
files - 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
cd
into 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.sql
or 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