-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.bitrix.yml
More file actions
1538 lines (1264 loc) · 42.1 KB
/
docker-compose.bitrix.yml
File metadata and controls
1538 lines (1264 loc) · 42.1 KB
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# ============================================================================
# DOCKER COMPOSE ДЛЯ 1С-БИТРИКС
# Единый Bitrix контейнер + оптимизированная структура
# Поддержка окружений: local, dev, test, prod
# Кросс-платформенность: Linux, macOS, Windows
# ============================================================================
name: ${COMPOSE_PROJECT_NAME:-bitrix}
# ============================================================================
# X-TEMPLATES: ПЕРЕИСПОЛЬЗУЕМЫЕ КОНФИГУРАЦИИ
# ============================================================================
# Volumes шаблоны
x-volumes:
# Основной код приложения (мультисайт)
# Структура: www/${DOMAIN}/www/ — каждый сайт в своей папке
app-code: &app-code
type: bind
source: ./www
target: /home/${UGN}/app
# Конфигурационные файлы
# NOTE: msmtp config is generated dynamically in entrypoint based on ENVIRONMENT
# Per-site SMTP configs are in ./config/sites/{domain}/msmtp.conf
# NOTE: dcron in Alpine requires root crontab for reliable execution
# Base crontab is read-only; entrypoint merges it with per-site crontabs
crontab: &crontab ./config/cron/crontab:/etc/crontabs/root.base:ro
# Per-site configurations (DB credentials, SMTP, etc.)
sites-config: &sites-config ./config/sites:/etc/bitrix-sites:ro
# Redis unix socket (shared between redis and php containers)
redis-socket: &redis-socket redis-socket:/var/run/redis
# Логи (доступны и для хоста и для Promtail)
logs-nginx: &logs-nginx ./volume/logs/nginx:/var/log/nginx
logs-letsencrypt: &logs-letsencrypt ./volume/logs/letsencrypt:/var/log/letsencrypt
logs-php: &logs-php ./volume/logs/php:/var/log/php
logs-php-fpm: &logs-php-fpm ./volume/logs/php-fpm:/var/log/php-fpm
logs-cron: &logs-cron ./volume/logs/cron:/var/log/cron
logs-supervisor: &logs-supervisor ./volume/logs/supervisor:/var/log/supervisor
logs-bitrix: &logs-bitrix ./volume/logs/bitrix:/var/log/bitrix
# Бэкапы и SSL
backup-data: &backup-data ./backups:/backups
ssl-certs: &ssl-certs ./ssl:/etc/nginx/ssl
letsencrypt-certs: &letsencrypt-certs /etc/letsencrypt:/etc/letsencrypt
# Docker логи для Promtail
docker-logs: &docker-logs /var/lib/docker/containers:/var/lib/docker/containers:ro
# Зависимости для PHP контейнеров
x-depends-on-all: &depends-on-all
mysql:
condition: service_healthy
redis:
condition: service_healthy
memcached:
condition: service_healthy
# Общие переменные окружения для Bitrix
x-bitrix-env: &bitrix-env
TZ: ${TZ}
BITRIX_VA_VER: ${BITRIX_VM_VER}
APP_ENV: ${ENVIRONMENT}
APP_DEBUG: ${DEBUG}
PHP_IDE_CONFIG: serverName=${DOMAIN}
XDEBUG_SESSION: docker-server
# Database
DB_HOST: ${DB_HOST:-mysql}
DB_PORT: ${DB_PORT:-3306}
DB_NAME: ${DB_NAME}
DB_USERNAME: ${DB_USERNAME}
DB_PASSWORD: ${DB_PASSWORD}
# Cache
REDIS_HOST: ${REDIS_HOST:-redis}
REDIS_PORT: ${REDIS_PORT:-6379}
REDIS_UNIX_SOCKET: /var/run/redis/redis.sock
MEMCACHED_HOST: ${MEMCACHED_HOST:-memcached}
MEMCACHED_PORT: 11211
# Queue (if RabbitMQ enabled)
RABBITMQ_HOST: ${RABBITMQ_HOST:-amqp}
RABBITMQ_PORT: ${RABBITMQ_PORT:-5672}
RABBITMQ_USER: ${RABBITMQ_DEFAULT_USER}
RABBITMQ_PASSWORD: ${RABBITMQ_DEFAULT_PASS}
# Push Server
PUSH_SECURITY_KEY: ${PUSH_SECURITY_KEY:-}
# Logging configuration
x-logging: &default-logging
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
# ==========================================================================
# SECURITY HARDENING (Bitrix official)
# Based on https://github.com/bitrix-tools/env-docker
# ==========================================================================
# Base security options for all containers
# NOTE: no-new-privileges removed globally — most containers need chmod/chown/gosu
# in entrypoints which requires privilege operations. Security is maintained via
# cap_drop: ALL + minimal cap_add per service.
x-security-base: &security-base
init: true
# tmpfs mounts for security (noexec, nodev, nosuid)
x-tmpfs-secure: &tmpfs-secure
tmpfs:
- /tmp:noexec,nodev,nosuid
- /var/tmp:noexec,nodev,nosuid
# Minimal capabilities (drop all, add only needed)
x-cap-minimal: &cap-minimal
cap_drop:
- ALL
# Capabilities for services that need file operations
x-cap-files: &cap-files
cap_drop:
- ALL
cap_add:
- CHOWN
- SETUID
- SETGID
- FOWNER
- DAC_OVERRIDE
# Capabilities for nginx (needs NET_BIND_SERVICE for ports < 1024)
x-cap-nginx: &cap-nginx
cap_drop:
- ALL
cap_add:
- CHOWN
- SETUID
- SETGID
- NET_BIND_SERVICE
# ============================================================================
# SERVICES
# ============================================================================
services:
# ==========================================================================
# BITRIX - ЕДИНЫЙ КОНТЕЙНЕР С PHP-FPM + CLI + CRON + SUPERVISOR
# ==========================================================================
bitrix:
container_name: ${DOMAIN}_bitrix
hostname: ${DOMAIN}
build:
context: .
dockerfile: docker/php/bitrix/Dockerfile
args:
PHP_VERSION: ${PHP_VERSION:-8.3}
TZ: ${TZ}
ENVIRONMENT: ${ENVIRONMENT}
DOMAIN: ${DOMAIN}
EMAIL: ${EMAIL}
SSL: ${SSL:-0}
UID: ${UID}
GID: ${GID}
UGN: ${UGN}
DEBUG: ${DEBUG:-0}
# Используем buildkit для ускорения сборки
cache_from:
- ${DOMAIN}_bitrix:latest
environment:
<<: *bitrix-env
# PHP-FPM настройки
PHP_FPM_PM: ${PHP_FPM_PM:-dynamic}
PHP_FPM_MAX_CHILDREN: ${PHP_FPM_MAX_CHILDREN:-50}
PHP_FPM_START_SERVERS: ${PHP_FPM_START_SERVERS:-5}
PHP_FPM_MIN_SPARE_SERVERS: ${PHP_FPM_MIN_SPARE_SERVERS:-5}
PHP_FPM_MAX_SPARE_SERVERS: ${PHP_FPM_MAX_SPARE_SERVERS:-35}
# PHP настройки
PHP_MEMORY_LIMIT: ${PHP_MEMORY_LIMIT:-256M}
PHP_UPLOAD_MAX_FILESIZE: ${PHP_UPLOAD_MAX_FILESIZE:-64M}
PHP_POST_MAX_SIZE: ${PHP_POST_MAX_SIZE:-64M}
PHP_MAX_EXECUTION_TIME: ${PHP_MAX_EXECUTION_TIME:-300}
PHP_MAX_INPUT_TIME: ${PHP_MAX_INPUT_TIME:-300}
# OPcache (Bitrix official recommendations)
PHP_OPCACHE_ENABLE: ${PHP_OPCACHE_ENABLE:-1}
PHP_OPCACHE_MEMORY: ${PHP_OPCACHE_MEMORY:-256}
PHP_OPCACHE_INTERNED_STRINGS: ${PHP_OPCACHE_INTERNED_STRINGS:-64}
PHP_OPCACHE_MAX_FILES: ${PHP_OPCACHE_MAX_FILES:-100000}
PHP_OPCACHE_REVALIDATE_FREQ: ${PHP_OPCACHE_REVALIDATE_FREQ:-2}
volumes:
# Основной код приложения (мультисайт: www/${DOMAIN}/www/)
- *app-code
# Конфигурации
- *crontab
- *sites-config
# Логи
- *logs-php
- *logs-php-fpm
- *logs-cron
- *logs-supervisor
- *logs-bitrix
# MSMTP логи (per-site)
- ./volume/logs/msmtp:/var/log/msmtp
# Composer cache (для ускорения установки зависимостей)
- composer-cache:/home/${UGN}/.composer
# Redis unix socket (shared volume for ~30% performance boost)
- *redis-socket
depends_on:
<<: *depends-on-all
nginx:
condition: service_healthy
mailhog:
condition: service_healthy
required: false
# Expose порт PHP-FPM для nginx
expose:
- "9000"
# Для dev окружения можно открыть порт для прямого доступа
# ports:
# - "9000:9000"
networks:
- bitrix-network
restart: unless-stopped
logging: *default-logging
# Security hardening (Bitrix official)
init: true
cap_drop:
- ALL
cap_add:
- CHOWN
- SETUID
- SETGID
- FOWNER
- DAC_OVERRIDE
tmpfs:
- /tmp:noexec,nodev,nosuid
- /var/tmp:noexec,nodev,nosuid
# Health check
healthcheck:
test: ["CMD", "/usr/local/bin/healthcheck"]
interval: 30s
timeout: 10s
start_period: 40s
retries: 3
# Labels для Prometheus и мониторинга
labels:
- "com.docker.compose.project=${COMPOSE_PROJECT_NAME:-bitrix}"
- "com.docker.compose.service=bitrix"
- "monitoring=true"
- "prometheus.scrape=true"
- "prometheus.port=9000"
# ==========================================================================
# SPLIT ARCHITECTURE - РАЗДЕЛЬНЫЕ PHP-КОНТЕЙНЕРЫ (АЛЬТЕРНАТИВА)
# ==========================================================================
# Запуск: docker compose --profile split up -d
# В этом режиме вместо единого "bitrix" контейнера используются 4 отдельных:
# php-fpm — обработка HTTP-запросов через FastCGI
# php-cli — CLI-операции, composer, миграции, интерактивный доступ
# cron — периодические задачи (agents, crontab)
# supervisor — фоновые воркеры (очереди, long-running процессы)
#
# ВАЖНО: При использовании split-профиля НЕ запускайте "bitrix" сервис!
# Nginx должен быть настроен на upstream "php-fpm" вместо "bitrix"
# (см. переменную PHP_FPM_HOST в секции nginx)
# ==========================================================================
# --------------------------------------------------------------------------
# PHP-FPM — FastCGI process manager для обработки HTTP-запросов
# --------------------------------------------------------------------------
php-fpm:
profiles: ["split"]
container_name: ${DOMAIN}_php-fpm
hostname: ${DOMAIN}
build:
context: .
dockerfile: docker/php/php-fpm/Dockerfile
args:
PHP_VERSION: ${PHP_VERSION:-8.3}
TZ: ${TZ}
ENVIRONMENT: ${ENVIRONMENT}
DOMAIN: ${DOMAIN}
EMAIL: ${EMAIL}
SSL: ${SSL:-0}
UID: ${UID}
GID: ${GID}
UGN: ${UGN}
DEBUG: ${DEBUG:-0}
environment:
<<: *bitrix-env
# PHP-FPM settings
PHP_FPM_PM: ${PHP_FPM_PM:-dynamic}
PHP_FPM_MAX_CHILDREN: ${PHP_FPM_MAX_CHILDREN:-50}
PHP_FPM_START_SERVERS: ${PHP_FPM_START_SERVERS:-5}
PHP_FPM_MIN_SPARE_SERVERS: ${PHP_FPM_MIN_SPARE_SERVERS:-5}
PHP_FPM_MAX_SPARE_SERVERS: ${PHP_FPM_MAX_SPARE_SERVERS:-35}
# PHP settings
PHP_MEMORY_LIMIT: ${PHP_MEMORY_LIMIT:-256M}
PHP_UPLOAD_MAX_FILESIZE: ${PHP_UPLOAD_MAX_FILESIZE:-64M}
PHP_POST_MAX_SIZE: ${PHP_POST_MAX_SIZE:-64M}
PHP_MAX_EXECUTION_TIME: ${PHP_MAX_EXECUTION_TIME:-300}
PHP_MAX_INPUT_TIME: ${PHP_MAX_INPUT_TIME:-300}
# OPcache (Bitrix official recommendations)
PHP_OPCACHE_ENABLE: ${PHP_OPCACHE_ENABLE:-1}
PHP_OPCACHE_MEMORY: ${PHP_OPCACHE_MEMORY:-256}
PHP_OPCACHE_INTERNED_STRINGS: ${PHP_OPCACHE_INTERNED_STRINGS:-64}
PHP_OPCACHE_MAX_FILES: ${PHP_OPCACHE_MAX_FILES:-100000}
PHP_OPCACHE_REVALIDATE_FREQ: ${PHP_OPCACHE_REVALIDATE_FREQ:-2}
volumes:
- *app-code
- *sites-config
- *logs-php
- *logs-php-fpm
- *logs-bitrix
# MSMTP logs (per-site)
- ./volume/logs/msmtp:/var/log/msmtp
# Redis unix socket (shared volume for ~30% performance boost)
- *redis-socket
depends_on:
<<: *depends-on-all
nginx:
condition: service_healthy
expose:
- "9000"
networks:
- bitrix-network
restart: unless-stopped
logging: *default-logging
# Security hardening (Bitrix official)
init: true
cap_drop:
- ALL
cap_add:
- CHOWN
- SETUID
- SETGID
- FOWNER
- DAC_OVERRIDE
tmpfs:
- /tmp:noexec,nodev,nosuid
- /var/tmp:noexec,nodev,nosuid
healthcheck:
test: ["CMD-SHELL", "REDIRECT_STATUS=true SCRIPT_NAME=/ping SCRIPT_FILENAME=/ping REQUEST_METHOD=GET cgi-fcgi -bind -connect 127.0.0.1:9000 || exit 1"]
interval: 30s
timeout: 10s
start_period: 40s
retries: 3
labels:
- "com.docker.compose.service=php-fpm"
- "monitoring=true"
- "prometheus.scrape=true"
- "prometheus.port=9000"
# --------------------------------------------------------------------------
# PHP-CLI — CLI operations, composer, migrations, interactive access
# --------------------------------------------------------------------------
php-cli:
profiles: ["split"]
container_name: ${DOMAIN}_php-cli
hostname: ${DOMAIN}
build:
context: .
dockerfile: docker/php/php-cli/Dockerfile
args:
PHP_VERSION: ${PHP_VERSION:-8.3}
TZ: ${TZ}
ENVIRONMENT: ${ENVIRONMENT}
DOMAIN: ${DOMAIN}
EMAIL: ${EMAIL}
SSL: ${SSL:-0}
UID: ${UID}
GID: ${GID}
UGN: ${UGN}
DEBUG: ${DEBUG:-0}
environment:
<<: *bitrix-env
# PHP settings for CLI (higher limits for migrations/imports)
PHP_MEMORY_LIMIT: ${PHP_CLI_MEMORY_LIMIT:-512M}
PHP_MAX_EXECUTION_TIME: ${PHP_CLI_MAX_EXECUTION_TIME:-0}
volumes:
- *app-code
- *sites-config
- *logs-php
- *logs-bitrix
# MSMTP logs (per-site)
- ./volume/logs/msmtp:/var/log/msmtp
# Composer cache for faster dependency installation
- composer-cache:/home/${UGN}/.composer
# Redis unix socket
- *redis-socket
depends_on:
mysql:
condition: service_healthy
redis:
condition: service_healthy
memcached:
condition: service_healthy
networks:
- bitrix-network
restart: unless-stopped
logging: *default-logging
# Keep running for exec access (docker compose exec php-cli bash)
tty: true
stdin_open: true
# Security hardening (Bitrix official)
init: true
cap_drop:
- ALL
cap_add:
- CHOWN
- SETUID
- SETGID
- FOWNER
- DAC_OVERRIDE
tmpfs:
- /tmp:noexec,nodev,nosuid
- /var/tmp:noexec,nodev,nosuid
healthcheck:
test: ["CMD-SHELL", "php -r 'echo \"ok\";' || exit 1"]
interval: 60s
timeout: 10s
start_period: 10s
retries: 3
labels:
- "com.docker.compose.service=php-cli"
# --------------------------------------------------------------------------
# CRON — Periodic tasks (Bitrix agents, scheduled jobs)
# --------------------------------------------------------------------------
cron:
profiles: ["split"]
container_name: ${DOMAIN}_cron
hostname: ${DOMAIN}
build:
context: .
dockerfile: docker/php/cron/Dockerfile
args:
PHP_VERSION: ${PHP_VERSION:-8.3}
TZ: ${TZ}
ENVIRONMENT: ${ENVIRONMENT}
DOMAIN: ${DOMAIN}
EMAIL: ${EMAIL}
SSL: ${SSL:-0}
UID: ${UID}
GID: ${GID}
UGN: ${UGN}
DEBUG: ${DEBUG:-0}
environment:
<<: *bitrix-env
PHP_MEMORY_LIMIT: ${PHP_MEMORY_LIMIT:-256M}
PHP_MAX_EXECUTION_TIME: ${PHP_MAX_EXECUTION_TIME:-300}
volumes:
- *app-code
- *crontab
- *sites-config
- *logs-cron
- *logs-php
- *logs-bitrix
# MSMTP logs (per-site)
- ./volume/logs/msmtp:/var/log/msmtp
# Redis unix socket
- *redis-socket
depends_on:
php-fpm:
condition: service_healthy
mysql:
condition: service_healthy
redis:
condition: service_healthy
networks:
- bitrix-network
restart: unless-stopped
logging: *default-logging
# Security hardening (Bitrix official)
init: true
cap_drop:
- ALL
cap_add:
- CHOWN
- SETUID
- SETGID
- FOWNER
- DAC_OVERRIDE
tmpfs:
- /tmp:noexec,nodev,nosuid
- /var/tmp:noexec,nodev,nosuid
healthcheck:
test: ["CMD-SHELL", "pgrep crond || pgrep cron || exit 1"]
interval: 30s
timeout: 10s
start_period: 10s
retries: 3
labels:
- "com.docker.compose.service=cron"
# --------------------------------------------------------------------------
# SUPERVISOR — Background workers (queues, long-running processes)
# --------------------------------------------------------------------------
supervisor:
profiles: ["split"]
container_name: ${DOMAIN}_supervisor
hostname: ${DOMAIN}
build:
context: .
dockerfile: docker/php/supervisor/Dockerfile
args:
PHP_VERSION: ${PHP_VERSION:-8.3}
TZ: ${TZ}
ENVIRONMENT: ${ENVIRONMENT}
DOMAIN: ${DOMAIN}
EMAIL: ${EMAIL}
SSL: ${SSL:-0}
UID: ${UID}
GID: ${GID}
UGN: ${UGN}
DEBUG: ${DEBUG:-0}
environment:
<<: *bitrix-env
PHP_MEMORY_LIMIT: ${PHP_MEMORY_LIMIT:-256M}
PHP_MAX_EXECUTION_TIME: ${PHP_MAX_EXECUTION_TIME:-300}
volumes:
- *app-code
- ./config/supervisor/conf:/etc/supervisor/conf.d
- *sites-config
- *logs-supervisor
- *logs-php
- *logs-bitrix
# MSMTP logs (per-site)
- ./volume/logs/msmtp:/var/log/msmtp
# Redis unix socket
- *redis-socket
depends_on:
php-fpm:
condition: service_healthy
mysql:
condition: service_healthy
redis:
condition: service_healthy
networks:
- bitrix-network
restart: unless-stopped
logging: *default-logging
# Security hardening (Bitrix official)
init: true
cap_drop:
- ALL
cap_add:
- CHOWN
- SETUID
- SETGID
- FOWNER
- DAC_OVERRIDE
tmpfs:
- /tmp:noexec,nodev,nosuid
- /var/tmp:noexec,nodev,nosuid
healthcheck:
test: ["CMD-SHELL", "supervisorctl status || exit 1"]
interval: 30s
timeout: 10s
start_period: 20s
retries: 3
labels:
- "com.docker.compose.service=supervisor"
# ==========================================================================
# NGINX - ВЕБ-СЕРВЕР
# ==========================================================================
nginx:
container_name: ${DOMAIN}_nginx
hostname: nginx
build:
context: .
dockerfile: docker/nginx/Dockerfile
args:
TZ: ${TZ}
ENVIRONMENT: ${ENVIRONMENT}
SSL: ${SSL:-0}
DOMAIN: ${DOMAIN}
EMAIL: ${EMAIL}
MAIL_CONFIG: ${MAIL_CONFIG:-0}
RABBIT_CONFIG: ${RABBIT_CONFIG:-0}
GRAFANA_CONFIG: ${GRAFANA_CONFIG:-0}
PROMETHEUS_CONFIG: ${PROMETHEUS_CONFIG:-0}
MAIL_SUBDOMAIN: ${MAIL_SUBDOMAIN:-mail}
RABBIT_SUBDOMAIN: ${RABBIT_SUBDOMAIN:-rabbit}
GRAFANA_SUBDOMAIN: ${GRAFANA_SUBDOMAIN:-grafana}
PROMETHEUS_SUBDOMAIN: ${PROMETHEUS_SUBDOMAIN:-prometheus}
DOLLAR: $$
UID: ${UID}
GID: ${GID}
UGN: ${UGN}
# FIXME: Nginx master process needs to run as root to bind ports and write PID file
# user: "${UID}:${GID}"
environment:
TZ: ${TZ}
# FastCGI backend
# DEFAULT (unified mode): PHP_FPM_HOST=bitrix (single "bitrix" container)
# SPLIT MODE: Set PHP_FPM_HOST=php-fpm in .env when using --profile split
# This controls the upstream for fastcgi_pass in nginx config
PHP_FPM_HOST: ${PHP_FPM_HOST:-bitrix}
PHP_FPM_PORT: 9000
# Monitoring basic auth (for grafana, prometheus, rabbit subdomains)
MONITORING_USER: ${MONITORING_USER:-admin}
MONITORING_PASSWORD: ${MONITORING_PASSWORD:-}
volumes:
- *app-code
- *logs-nginx
- *logs-letsencrypt
- *ssl-certs
- *letsencrypt-certs
# Мультисайтовые конфиги и SSL
- ./config/nginx/sites:/etc/nginx/sites-enabled
- ./config/nginx/ssl:/etc/nginx/ssl:ro
# Per-site custom nginx rules (redirects, rewrites, etc.)
- *sites-config
# depends_on убран чтобы избежать циклической зависимости с bitrix
# nginx может запускаться независимо и будет отдавать 502 пока PHP-FPM недоступен
ports:
- "${HTTP_PORT:-80}:80"
- "${HTTPS_PORT:-443}:443"
networks:
- bitrix-network
restart: unless-stopped
logging: *default-logging
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:80/health || exit 1"]
interval: 10s
timeout: 5s
start_period: 10s
retries: 3
# Security hardening
# NOTE: no-new-privileges DISABLED for Nginx — master process runs as root
# and uses setuid() to switch workers to bitrix user via "user bitrix;" directive.
init: true
cap_drop:
- ALL
cap_add:
- CHOWN
- SETUID
- SETGID
- NET_BIND_SERVICE
tmpfs:
- /tmp:noexec,nodev,nosuid
- /var/tmp:noexec,nodev,nosuid
labels:
- "com.docker.compose.service=nginx"
- "monitoring=true"
# ==========================================================================
# MYSQL - БАЗА ДАННЫХ
# ==========================================================================
# Выбор движка базы данных (MYSQL_IMAGE в .env):
# ─────────────────────────────────────────────────────────────────────────
# RAM < 4GB: mariadb:10.11 (default, низкое потребление памяти)
# RAM 4-16GB: quay.io/bitrix24/percona-server:8.0.44-v1-rhel (Bitrix official)
# RAM > 16GB: quay.io/bitrix24/percona-server:8.4.7-v1-rhel (новейшая версия)
# Alternative: mysql:8.0 или mysql:8.4 (официальный MySQL)
# ─────────────────────────────────────────────────────────────────────────
mysql:
container_name: ${DOMAIN}_mysql
# Bitrix official: quay.io/bitrix24/percona-server:8.0.44-v1-rhel
# Default: mariadb:10.11 for low RAM environments
image: ${MYSQL_IMAGE:-mariadb:10.11}
command:
# NOTE: --default-authentication-plugin is MySQL-only, not supported by MariaDB
# For MySQL 8.0+, authentication is configured via mysql_native_password plugin
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_unicode_ci
- --sql-mode=NO_ENGINE_SUBSTITUTION
# FIXME: O_DIRECT causes issues on macOS/ARM
# - --innodb-flush-method=O_DIRECT
- --innodb-buffer-pool-size=${MYSQL_INNODB_BUFFER_POOL_SIZE:-512M}
- --max-connections=${MYSQL_MAX_CONNECTIONS:-200}
# Disable error log file (use stderr for Docker logs)
- --log-error=
environment:
TZ: ${TZ}
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
MYSQL_DATABASE: ${DB_NAME}
MYSQL_USER: ${DB_USERNAME}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_EXPORTER_PASSWORD: ${MYSQL_EXPORTER_PASSWORD:-exporter_password}
volumes:
- mysql-data:/var/lib/mysql
- ./volume/logs/mysql:/var/log/mysql
- ./volume/mysql/dump:/dump
- ./config/mysql/my.${ENVIRONMENT}.cnf:/etc/mysql/conf.d/bitrix.cnf:ro
- ./config/mysql/init:/docker-entrypoint-initdb.d:ro
# SECURITY: Port closed for production - MySQL only accessible within Docker network
# Uncomment for development/debugging only:
# ports:
# - "${DB_PORT:-3306}:3306"
networks:
- bitrix-network
restart: unless-stopped
logging: *default-logging
healthcheck:
# NOTE: Using healthcheck.sh wrapper for better diagnostics
# Falls back to mysqladmin ping if script not available
test: ["CMD-SHELL", "mysqladmin ping -h localhost -u root -p\"$${MYSQL_ROOT_PASSWORD}\" --silent || exit 1"]
interval: 10s
timeout: 5s
retries: 10
start_period: 120s
# Resource limits для продакшн
deploy:
resources:
limits:
memory: ${MYSQL_MEMORY_LIMIT:-2G}
reservations:
memory: ${MYSQL_MEMORY_RESERVATION:-1G}
# Security hardening
# NOTE: no-new-privileges DISABLED for MySQL/MariaDB — entrypoint uses
# gosu to switch from root to mysql user, which requires setuid syscall.
init: true
cap_drop:
- ALL
cap_add:
- SYS_NICE
- SETUID
- SETGID
- DAC_OVERRIDE
tmpfs:
- /tmp:noexec,nodev,nosuid
- /var/tmp:noexec,nodev,nosuid
labels:
- "com.docker.compose.service=mysql"
- "monitoring=true"
# ==========================================================================
# REDIS - КЭШИРОВАНИЕ
# ==========================================================================
redis:
container_name: ${DOMAIN}_redis
build:
context: .
dockerfile: docker/redis/Dockerfile
args:
TZ: ${TZ}
command: >
redis-server
/usr/local/etc/redis/redis.conf
--maxmemory ${REDIS_MAX_MEMORY:-512mb}
environment:
TZ: ${TZ}
volumes:
- redis-data:/data
- ./volume/logs/redis:/var/log/redis
- ./config/redis/redis.conf:/usr/local/etc/redis/redis.conf:ro
# Unix socket shared with PHP container
- *redis-socket
# Redis port NOT exposed to host for security (no password configured)
# Containers communicate via Docker network or unix socket
# Uncomment for debugging: ports: ["${REDIS_PORT:-6379}:6379"]
networks:
- bitrix-network
restart: unless-stopped
logging: *default-logging
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 30s
timeout: 10s
retries: 3
# Security hardening (Bitrix official)
init: true
cap_drop:
- ALL
cap_add:
- CHOWN
- SETUID
- SETGID
tmpfs:
- /tmp:noexec,nodev,nosuid
- /var/tmp:noexec,nodev,nosuid
labels:
- "com.docker.compose.service=redis"
- "monitoring=true"
# ==========================================================================
# PUSH SERVER - REAL-TIME УВЕДОМЛЕНИЯ
# ==========================================================================
# Push & Pull модуль Bitrix для мгновенных уведомлений, чата, живой ленты
# Документация: https://dev.1c-bitrix.ru/learning/course/index.php?COURSE_ID=41&LESSON_ID=2033
# Сервис подписок (клиенты подключаются сюда через WebSocket)
push-sub:
image: quay.io/bitrix24/push:3.2-v1-alpine
container_name: ${DOMAIN}_push_sub
environment:
- PUSH_SECURITY_KEY=${PUSH_SECURITY_KEY:-}
- PUSH_SUB_PORT=8010
- PUSH_SUB_MODE=sub
- REDIS_HOST=${REDIS_HOST:-redis}
- REDIS_PORT=${REDIS_PORT:-6379}
depends_on:
redis:
condition: service_healthy
networks:
- bitrix-network
restart: unless-stopped
logging: *default-logging
healthcheck:
test: ["CMD-SHELL", "nc -z localhost 8010 || exit 1"]
interval: 30s
timeout: 10s
retries: 3
# Security hardening (Bitrix official)
init: true
cap_drop:
- ALL
tmpfs:
- /tmp:noexec,nodev,nosuid
- /var/tmp:noexec,nodev,nosuid
profiles:
- push
- full
labels:
- "com.docker.compose.service=push-sub"
# Сервис публикации (PHP отправляет сюда события)
push-pub:
image: quay.io/bitrix24/push:3.2-v1-alpine
container_name: ${DOMAIN}_push_pub
environment:
- PUSH_SECURITY_KEY=${PUSH_SECURITY_KEY:-}
- PUSH_PUB_PORT=9010
- PUSH_PUB_MODE=pub
- REDIS_HOST=${REDIS_HOST:-redis}
- REDIS_PORT=${REDIS_PORT:-6379}
depends_on:
redis:
condition: service_healthy
networks:
- bitrix-network
restart: unless-stopped
logging: *default-logging
healthcheck:
test: ["CMD-SHELL", "nc -z localhost 9010 || exit 1"]
interval: 30s
timeout: 10s
retries: 3
# Security hardening (Bitrix official)
init: true
cap_drop:
- ALL
tmpfs:
- /tmp:noexec,nodev,nosuid
- /var/tmp:noexec,nodev,nosuid
profiles:
- push
- full
labels:
- "com.docker.compose.service=push-pub"
# ==========================================================================
# MEMCACHED - ADDITIONAL CACHING (production-proven settings)
# ==========================================================================
memcached:
container_name: ${DOMAIN}_memcached
build:
context: .
dockerfile: docker/memcached/Dockerfile
args:
TZ: ${TZ}
MEMCACHED_MEMORY_LIMIT: ${MEMCACHED_MEMORY_LIMIT:-1024}
MEMCACHED_THREADS: ${MEMCACHED_THREADS:-8}
MEMCACHED_CONN_LIMIT: ${MEMCACHED_CONN_LIMIT:-1024}
MEMCACHED_MAX_ITEM_SIZE: ${MEMCACHED_MAX_ITEM_SIZE:-2m}
environment:
TZ: ${TZ}
command: >-
memcached -u root
-m ${MEMCACHED_MEMORY_LIMIT:-1024}
-c ${MEMCACHED_CONN_LIMIT:-1024}
-t ${MEMCACHED_THREADS:-8}
-I ${MEMCACHED_MAX_ITEM_SIZE:-2m}
-o modern
volumes:
- ./volume/logs/memcached:/var/log/memcached
networks:
- bitrix-network
restart: unless-stopped
logging: *default-logging
healthcheck:
test: ["CMD", "nc", "-z", "localhost", "11211"]
interval: 30s
timeout: 10s
retries: 3
# Security hardening
# NOTE: no-new-privileges DISABLED for Memcached — process needs to
# drop supplementary groups which requires privilege operations.
init: true
cap_drop:
- ALL
cap_add: