MariaDB¶
The MariaDB container provides the relational database backend for the PHP application. It is configured for persistence, remote connectivity, and flexible overrides through environment variables.
Dockerfile: devops/{env}/mysql/Dockerfile
Persistent data storage¶
Data is stored persistently between container restarts via a volume mount:
Environment variables¶
All credentials and connection settings are defined in your .env file and injected into the container:
environment:
- MARIADB_ROOT_PASSWORD=${DB_ROOT_PASSWORD}
- MARIADB_DATABASE=${DB_NAME}
- MARIADB_USER=${DB_USER}
- MARIADB_PASSWORD=${DB_PASSWORD}
| Variable | Purpose |
|---|---|
DB_ROOT_PASSWORD | Root password for MariaDB |
DB_NAME | Name of the database to create |
DB_USER | Custom username |
DB_PASSWORD | Password for the user |
Remote connection¶
MariaDB is exposed on the host via port 3307 (mapped from internal 3306):
Connect from a local client (e.g., DataGrip):
| Setting | Value |
|---|---|
| Host | localhost |
| Port | 3307 |
| Username | ${DB_USER} |
| Password | ${DB_PASSWORD} |
| Database | ${DB_NAME} |
Health check¶
The container runs a health check before dependent services (e.g., PHP) start, preventing connection race conditions on startup:
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 10s
timeout: 5s
retries: 5
Service configuration¶
| Property | Value |
|---|---|
| Dockerfile | devops/{env}/mysql/Dockerfile |
| Internal port | 3306 → exposed as 3307 on host |
| Network | barberklingen-<site>-network |
| Volume | ./devops/prod/mysql:/var/lib/mysql/data |
Troubleshooting¶
Docker network host permission errors¶
Even when networking is correctly configured, MariaDB may refuse connections if the MySQL user was created with 'user'@'localhost' rather than a host matching the Docker network IP range.
Symptom: PHP can reach the MariaDB container by hostname, but authentication fails.
Fix:
Check the Docker network CIDR:
Grant the user access from the Docker IP range:
Verify connectivity from another container: