Docker окружение
Relevant source files
The following files were used as context for generating this wiki page:
The Docker environment in the Music Subscription Service project provides a standardized, containerized infrastructure for development and deployment. It orchestrates the Go backend application alongside essential storage services like PostgreSQL and Redis, ensuring consistency across different environments.
Sources: README.md:14-25, docker-compose.yml:1-73
Container Architecture
The system uses a multi-container architecture defined in the docker-compose.yml file. This setup separates the application logic from data persistence and caching layers, using internal Docker networking for communication between services.
Core Components
The environment consists of several key services:
- app: The main Go REST API application.
- postgres: Relational database for persistent data (users, tracks, playlists).
- redis: In-memory data store for caching and rate limiting.
- port-forwarders: Utility containers using
socatto expose database ports to the localhost during development.
The diagram above illustrates the relationship between the main application service, its dependencies, and the port-forwarding mechanism for local access.
Sources: docker-compose.yml:3-67, README.md:179-195
Service Configuration
Application Service (app)
The application container builds from the project root using a local Dockerfile. It relies on environment variables for service discovery within the Docker network.
| Configuration | Value / Source | Description |
|---|---|---|
| Container Name | music-app | Static container identifier |
| Port | 8080:8080 | Maps host port to internal application port |
| Env File | .env | Loads project-wide secrets and settings |
| Dependencies | postgres, redis | Requires healthy state before startup |
Sources: docker-compose.yml:4-21, internal/core/config/config.go:34-53
Storage Services
The database and cache services use official Alpine-based images to minimize container size and improve security.
- PostgreSQL 16: Configured with automated health checks using
pg_isready. Data is persisted in${PROJECT_ROOT}/out/pgdata. - Redis 7: Used for caching (e.g., track metadata). Health is monitored via
redis-cli ping. Data is persisted in${PROJECT_ROOT}/out/redisdata.
Sources: docker-compose.yml:23-45, cmd/app/main.go:76-88
Data Persistence and Logging
The Docker setup uses host volume mapping to ensure logs and database records persist across container restarts.
# Examples of volume mapping in docker-compose.yml
volumes:
- ${PROJECT_ROOT}/out/logs:/app/out/logs # Application logs
- ${PROJECT_ROOT}/out/pgdata:/var/lib/postgresql/data # DB persistence
- ${PROJECT_ROOT}/out/redisdata:/data # Cache persistence
Sources: docker-compose.yml:15-16, docker-compose.yml:32-33, internal/core/logger/logger.go:42-45
Deployment and CI/CD
Beyond local Docker Compose, the project includes configurations for cloud deployment using Fly.io.
Fly.io Integration
The fly.toml file defines the production runtime parameters, including resource limits and release commands that execute database migrations before the new version goes live.
The sequence above shows the automated flow from code commit to container deployment.
Sources: fly.toml:1-25, README.md:214-235
Summary
The Docker environment is the backbone of the Music Subscription Service's infrastructure. It provides a "one-click" setup via docker-compose up, ensures high availability through health checks, and simplifies the transition from local development to production deployment on Fly.io. By isolating dependencies like Postgres and Redis, the system maintains a predictable environment regardless of the host OS.
Sources: README.md:14-25, docker-compose.yml:1-73