1
1
services :
2
2
web :
3
- image : nginx:alpine
4
3
build :
5
4
context : ../../example-app
6
5
dockerfile : ../production/nginx-fpm/nginx/Dockerfile
6
+ restart : unless-stopped # Automatically restart unless the service is explicitly stopped
7
7
volumes :
8
- - laravel-storage:/var/www/storage:ro # Mount the storage volume (in case you want to use storage:link)
8
+ # Mount the 'laravel-storage' volume to '/var/www/storage' inside the container.
9
+ # -----------------------------------------------------------
10
+ # This volume stores persistent data like uploaded files and cache.
11
+ # The ':ro' option mounts it as read-only in the 'web' service because Nginx only needs to read these files.
12
+ # The 'php-fpm' service mounts the same volume without ':ro' to allow write operations.
13
+ # -----------------------------------------------------------
14
+ - laravel-storage:/var/www/storage:ro
9
15
networks :
10
16
- laravel
11
17
ports :
18
+ # Map port 80 inside the container to the port specified by 'NGINX_PORT' on the host machine.
19
+ # -----------------------------------------------------------
20
+ # This allows external access to the Nginx web server running inside the container.
21
+ # For example, if 'NGINX_PORT' is set to '8080', accessing 'http://localhost:8080' will reach the application.
22
+ # -----------------------------------------------------------
12
23
- " ${NGINX_PORT}:80"
13
- environment :
14
- - NGINX_HOST=${NGINX_HOST}
15
24
depends_on :
16
25
php-fpm :
17
26
condition : service_healthy # Wait for php-fpm health check
@@ -21,52 +30,61 @@ services:
21
30
build :
22
31
context : ../../example-app
23
32
dockerfile : ../production/nginx-fpm/php-fpm/Dockerfile
33
+ restart : unless-stopped
24
34
volumes :
25
35
- laravel-storage:/var/www/storage # Mount the storage volume
26
- environment :
27
- - APP_NAME=TestApp
28
- - APP_KEY=base64:y6S7gjyAO/PVAJMBvJSJUCO8qiz92qvcNAPRKH3hpj4=
29
- - APP_DEBUG=true
36
+ env_file :
37
+ - ../../example-app/.env
30
38
networks :
31
39
- laravel
32
40
healthcheck :
33
41
test : ["CMD-SHELL", "php-fpm-healthcheck || exit 1"]
34
42
interval : 10s
35
43
timeout : 5s
36
44
retries : 3
37
- # The `depends_on` section tells Docker Compose to
38
- # start the database before your application.
45
+ # The 'depends_on' attribute with 'condition: service_healthy' ensures that
46
+ # this service will not start until the 'postgres' service passes its health check.
47
+ # This prevents the application from trying to connect to the database before it's ready.
39
48
depends_on :
40
49
postgres :
41
50
condition : service_healthy
42
51
52
+ # The 'php-cli' service provides a command-line interface for running Artisan commands and other CLI tasks.
53
+ # -----------------------------------------------------------
54
+ # This is useful for running migrations, seeders, or any custom scripts.
55
+ # It shares the same codebase and environment as the 'php-fpm' service.
56
+ # -----------------------------------------------------------
43
57
php-cli :
44
58
build :
45
59
context : ../../example-app
46
60
dockerfile : ../production/nginx-fpm/php-cli/Dockerfile
47
- tty : true # Keep the terminal open
48
- stdin_open : true # Keep stdin open to attach to the container
49
- environment :
50
- - APP_NAME=TestApp
61
+ tty : true # Enables an interactive terminal
62
+ stdin_open : true # Keeps standard input open for 'docker exec'
63
+ env_file :
64
+ - ../../example-app/.env
51
65
networks :
52
66
- laravel
53
67
54
68
postgres :
55
69
image : postgres:16
56
- restart : always
70
+ restart : unless-stopped
57
71
user : postgres
58
- secrets :
59
- - db-password
60
72
ports :
61
- - " 5432 :5432"
73
+ - " ${POSTGRES_PORT} :5432"
62
74
environment :
63
- - POSTGRES_DB=${DB_DATABASE }
64
- - POSTGRES_USER=${DB_USERNAME }
65
- - POSTGRES_PASSWORD_FILE=/run/secrets/db-password
75
+ - POSTGRES_DB=${POSTGRES_DATABASE }
76
+ - POSTGRES_USER=${POSTGRES_USERNAME }
77
+ - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
66
78
volumes :
67
79
- postgres-data:/var/lib/postgresql/data
68
80
networks :
69
81
- laravel
82
+ # Health check for PostgreSQL
83
+ # -----------------------------------------------------------
84
+ # Health checks allow Docker to determine if a service is operational.
85
+ # The 'pg_isready' command checks if PostgreSQL is ready to accept connections.
86
+ # This prevents dependent services from starting before the database is ready.
87
+ # -----------------------------------------------------------
70
88
healthcheck :
71
89
test : [ "CMD", "pg_isready" ]
72
90
interval : 10s
@@ -75,21 +93,28 @@ services:
75
93
76
94
redis :
77
95
image : redis:alpine
96
+ restart : unless-stopped # Automatically restart unless the service is explicitly stopped
78
97
networks :
79
98
- laravel
99
+ # Health check for Redis
100
+ # -----------------------------------------------------------
101
+ # Checks if Redis is responding to the 'PING' command.
102
+ # This ensures that the service is not only running but also operational.
103
+ # -----------------------------------------------------------
80
104
healthcheck :
81
105
test : ["CMD", "redis-cli", "ping"]
82
106
interval : 10s
83
107
timeout : 5s
84
108
retries : 3
85
109
86
110
networks :
111
+ # Attach the service to the 'laravel' network.
112
+ # -----------------------------------------------------------
113
+ # This custom network allows all services within it to communicate using their service names as hostnames.
114
+ # For example, 'php-fpm' can connect to 'postgres' by using 'postgres' as the hostname.
115
+ # -----------------------------------------------------------
87
116
laravel :
88
117
89
118
volumes :
90
119
postgres-data :
91
120
laravel-storage :
92
-
93
- secrets :
94
- db-password :
95
- file : db-password.txt
0 commit comments