-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-compose.yml
75 lines (69 loc) · 3 KB
/
docker-compose.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
version: '3.8' # Specify the version of the Docker Compose file format
services:
# Nginx Web Server
web:
container_name: web
image: nginx:latest # Use the latest official Nginx image
ports:
- "80:80" # Map port 80 on the host to port 80 in the container
volumes:
- ./:/var/www/html # Mount the root directory to the web root inside the container
- ./Docker/nginx.conf:/etc/nginx/conf.d/default.conf # Use a custom Nginx configuration
depends_on:
- app # Ensure PHP-FPM service is started before Nginx
networks:
- app_network
# PHP-FPM Service
app:
container_name: app
build:
context: . # Use the current directory to build the Dockerfile
dockerfile: Dockerfile # Specify the Dockerfile
volumes:
- ./:/var/www/html # Mount the root directory to the web root inside the container
depends_on:
- composer # Ensure Composer runs before starting the app service
- mysql # Ensure MySQL is started before the app service
networks:
- app_network
# Composer service for managing PHP dependencies
composer:
container_name: composer
image: composer:2.2 # Use the official Composer image, version 2.2
working_dir: /var/www/html # Set the working directory inside the container
volumes:
- ./:/var/www/html # Mount the root directory to the web root inside the container
entrypoint: # Override the entrypoint to run Composer commands with specified options
- composer
- "--ignore-platform-reqs" # Ignore platform requirements during installation
- "--no-progress" # Disable progress display for cleaner output
- "--no-ansi" # Disable ANSI colors in the output
command: ["install"] # Install PHP dependencies defined in composer.json
# MySQL service for database interactions
mysql:
container_name: mysql
image: mysql:8.3 # Use MySQL version 8.3
ports:
- '${FORWARD_DB_PORT:-3306}:3306' # Dynamically set the port with an optional environment variable
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}' # Use environment variables for sensitive data
MYSQL_ROOT_HOST: "%"
MYSQL_DATABASE: '${DB_DATABASE}' # Set the database name from the environment
MYSQL_USER: '${DB_USERNAME}' # Set the database user from the environment
MYSQL_PASSWORD: '${DB_PASSWORD}' # Set the database password from the environment
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes' # Optionally allow empty passwords
volumes:
- mysql_data:/var/lib/mysql # Store MySQL data in a named volume
networks:
- app_network
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-p${DB_PASSWORD}"] # Check if MySQL is available
interval: 10s # Check every 10 seconds
retries: 3 # Retry 3 times before marking as unhealthy
timeout: 5s # Timeout after 5 seconds
networks:
app_network:
driver: bridge # Use the default bridge network driver
volumes:
mysql_data:
driver: local # Use local storage for MySQL data