Docker Deployment
App CR uses Docker Compose to orchestrate the PostgreSQL database and can be easily extended to containerize the entire application.Docker Compose Setup
The project includes adocker-compose.yml file that defines the PostgreSQL service:
docker-compose.yml
Services Overview
PostgreSQL Database
- Image: postgres:15
- Port: 5432 (mapped to host port 5432)
- Database: mi_db_crud
- Persistent Storage: postgres_data volume
Getting Started with Docker
Install Docker
Ensure you have Docker and Docker Compose installed on your system:
- Docker Desktop (Windows/Mac)
- Docker Engine (Linux)
Start the Database
Run the following command in your project root:The
-d flag runs containers in detached mode (background).Verify the Database is Running
Check the status of your containers:You should see the postgres service running on port 5432.
Docker Commands Reference
Database Management
Accessing the PostgreSQL Container
You can connect to the PostgreSQL database directly:Backup and Restore
Volume Management
The
postgres_data volume persists your database data between container restarts. This ensures you don’t lose data when updating or restarting containers.View Volumes
Remove Volumes
Extending the Setup
You can extend thedocker-compose.yml to include the backend application:
docker-compose.yml
Troubleshooting
Port Already in Use
If port 5432 is already in use, modify the port mapping indocker-compose.yml:
DATABASE_URL accordingly.
Connection Issues
If you can’t connect to the database:- Verify the container is running:
docker-compose ps - Check container logs:
docker-compose logs postgres - Ensure your
DATABASE_URLmatches the Docker configuration
Reset Everything
To completely reset your Docker setup:Next Steps
Environment Variables
Configure environment variables for your application
Production Deployment
Learn best practices for production deployments