Overview
Secure Link API can be deployed using Docker for both development and production environments. The project includes adocker-compose.yml file for easy MySQL setup.
Prerequisites
- Docker 20.10+
- Docker Compose 2.0+
Quick Start with Docker Compose
The provideddocker-compose.yml sets up MySQL 8.4 with the required configuration.
Configure Environment Variables
Create a Edit the
.env file in the backend/ directory:.env file:.env
Start MySQL Container
Launch the MySQL container using docker-compose:This will:
- Pull MySQL 8.4.8 image
- Create a persistent volume for data
- Configure the database with UTF-8 support
- Expose MySQL on port 3307
Docker Compose Configuration
Here’s the completedocker-compose.yml configuration:
docker-compose.yml
Configuration Details
| Setting | Description |
|---|---|
image: mysql:8.4.8 | Official MySQL 8.4 image |
restart: unless-stopped | Auto-restart container on failure |
MYSQL_DATABASE | Creates database on first run |
MYSQL_USER/PASSWORD | Application database user |
MYSQL_ROOT_PASSWORD | Root password (not used by app) |
TZ: America/Sao_Paulo | Container timezone |
mysql_data volume | Persistent storage for database |
--character-set-server=utf8mb4 | UTF-8 support for international characters |
Containerizing the Application
To run the entire application in Docker, create aDockerfile:
Dockerfile
Build and Run
Full Stack Docker Compose
For a complete deployment with both MySQL and the application:docker-compose.full.yml
Launch Full Stack
Docker Commands Reference
Container Management
Database Operations
Application Container
Volume Management
List Volumes
Inspect Volume
Backup Volume
Restore Volume
Production Deployment
Environment Variables for Production
.env.production
Docker Secrets (Swarm Mode)
For enhanced security in production:Health Checks
Monitor container health:Resource Limits
Set resource constraints:Troubleshooting
MySQL Connection Failed
Application Won’t Start
Port Conflicts
If port 3307 is in use:.env:
Data Persistence Issues
Next Steps
- Configure the application for your environment
- Install locally for development
- Review API Reference for usage
