-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-compose.yml
186 lines (149 loc) · 5.67 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
services:
##
# The web server container.
##
webserver:
build:
context: .
dockerfile: images/webserver.Dockerfile
target: dev
networks:
- default
- proxy
# These get parsed automagically now. See "Using environment variables in nginx configuration" at https://hub.docker.com/_/nginx/
environment:
SERVER_NAME: ${SERVER_NAME}
PHP_FPM_CONTAINER: app
volumes:
- wordpress:/var/www/html
- vendor:/var/www/vendor
- ./tools/local-env/nginx.conf.template:/etc/nginx/templates/default.conf.template
- ./wp-content:/var/www/html/wp-content # if you leave this out, nginx can't find uploaded files, despite them existing on your local machine
- ./extra-wp-config.php:/var/www/html/extra-wp-config.php
depends_on:
app:
condition: service_started
db:
condition: service_healthy
labels:
# Explicitly tell Traefik to expose this container
- traefik.enable=true
# Tell Traefik you are planning a redirection, and to include the needed middleware
- traefik.http.middlewares.wptestlocaldev-redirect-web-secure.redirectscheme.scheme=https
- traefik.http.routers.wptestlocaldev.middlewares=wptestlocaldev-redirect-web-secure
# The domain the service will respond to, and what is in your /etc/hosts
- traefik.http.routers.wptestlocaldev-web.rule=Host(`${SERVER_NAME}`)
# Allow request only from the predefined entry point named "web"
- traefik.http.routers.wptestlocaldev-web.entrypoints=web # this is working with the port 80 entrypoint in the traefik config (a different docker-compose.yml)
# Let's redirect!
- traefik.http.routers.wptestlocaldev-web-secure.rule=Host(`${SERVER_NAME}`)
- traefik.http.routers.wptestlocaldev-web-secure.tls=true
- traefik.http.routers.wptestlocaldev-web-secure.entrypoints=web-secure
# What is essentially in this container's Dockerfile or image's Dockerfile under the `EXPOSE` setting
- traefik.http.services.wptestlocaldev-web-secure.loadbalancer.server.port=80 # this can be anything, but mirror the change back to the Dockerfile via EXPOSE
##
# The PHP-FPM container that only holds WordPress
##
app:
build:
context: .
dockerfile: images/app.Dockerfile
target: dev
args:
LOCAL_PHP_VERSION: ${LOCAL_PHP_VERSION}
networks:
- default
env_file: .env
environment:
WORDPRESS_CONFIG_EXTRA: |
require_once ABSPATH . 'extra-wp-config.php';
volumes:
- ./tools/local-env/php-config.ini:/usr/local/etc/php/conf.d/php-config.ini
- ./tools/local-env/phpcs.xml.dist:/var/www/phpcs.xml.dist
- wordpress:/var/www/html
- vendor:/var/www/vendor
- ./wp-content:/var/www/html/wp-content
- ./extra-wp-config.php:/var/www/html/extra-wp-config.php
# The init directive ensures the command runs with a PID > 1, so Ctrl+C works correctly.
init: true
# Needed for the loopback events inside WordPress - leaving this out causes them to fail, as seen under Tools > Site Health
extra_hosts:
- ${SERVER_NAME}:host-gateway
##
# The database container. Either MySQL or MariaDB
##
db:
image: mariadb:${LOCAL_DB_VERSION-latest}
networks:
- default
- proxy
labels:
- traefik.enable=true
- traefik.tcp.routers.db-tcp.rule=HostSNI(`*`)
- traefik.tcp.routers.db-tcp.entrypoints=mysql
- traefik.tcp.routers.db-tcp.service=db-proxy
- traefik.tcp.services.db-proxy.loadbalancer.server.port=3306
environment:
MARIADB_USER: ${WORDPRESS_DB_USER}
MARIADB_ROOT_PASSWORD: ${WORDPRESS_DB_PASSWORD}
MARIADB_DATABASE: ${WORDPRESS_DB_NAME}
volumes:
- ./tools/local-env/mysql-init.sql:/docker-entrypoint-initdb.d/mysql-init.sql
- db:/var/lib/mysql
healthcheck:
test: [ "CMD-SHELL", "mariadb-admin --password=${WORDPRESS_DB_PASSWORD} ping -h localhost" ]
timeout: 5s
interval: 5s
retries: 10
##
# WP-CLI
##
cli:
build:
context: .
dockerfile: images/cli.Dockerfile
target: dev
args:
LOCAL_PHP_VERSION: ${LOCAL_PHP_VERSION}
# this is not ran when you run the container like `docker compose run cli bash`
command: wp core install --url=${SERVER_NAME} --title="WordPress Test" --admin_user=admin --admin_password=password --admin_email=admin@${SERVER_NAME} --skip-email
networks:
- default
env_file: .env
environment:
WORDPRESS_CONFIG_EXTRA: |
require_once ABSPATH . 'extra-wp-config.php';
depends_on:
app:
condition: service_started
db:
condition: service_healthy
volumes:
- wordpress:/var/www/html
- vendor:/var/www/vendor
- ./wp-content:/var/www/html/wp-content
- ./extra-wp-config.php:/var/www/html/extra-wp-config.php
# The init directive ensures the command runs with a PID > 1, so Ctrl+C works correctly.
init: true
composer:
image: composer:latest
volumes:
- wordpress:/var/www/html
- vendor:/var/www/vendor
- ./wp-content:/var/www/html/wp-content
- ./composer.json:/var/www/composer.json
# - ./composer.lock:/var/www/composer.lock # uncomment this when this is no longer a template and restart the container
working_dir: /var/www/
# this is not ran when you run the container like `docker compose run composer composer`
command: composer install
volumes:
db:
node_modules:
vendor:
wordpress:
networks:
# Creating our own network allows us to connect between containers using their service name.
default:
driver: bridge
proxy:
external: true