Deploying 1C-Bitrix in Docker
Deploying 1C-Bitrix in Docker
The official 1C-Bitrix position on Docker: "use BitrixVM". In practice this means Docker deployment requires manual configuration — there is no official image, no vendor-supplied docker-compose. But it delivers a reproducible environment, dependency isolation, and the ability to run the project identically on a developer's laptop, in CI/CD, and in production.
The main caveat: 1C-Bitrix requires specific PHP versions (8.1–8.2 for current editions), particular PHP extensions (iconv, mbstring, gd, opcache, memcached), and filesystem write access — which runs counter to the immutable containers principle. Solvable, but with an understanding of the trade-offs involved.
Docker Compose Structure
# docker-compose.yml
version: '3.9'
services:
nginx:
image: nginx:1.24-alpine
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx/conf.d:/etc/nginx/conf.d:ro
- ./nginx/ssl:/etc/nginx/ssl:ro
- bitrix_files:/var/www/html
depends_on:
- php-fpm
php-fpm:
build: ./docker/php
volumes:
- bitrix_files:/var/www/html
- ./docker/php/php.ini:/usr/local/etc/php/conf.d/bitrix.ini:ro
environment:
- DB_HOST=mysql
- DB_NAME=bitrix
- DB_USER=bitrix
- DB_PASS=${DB_PASSWORD}
depends_on:
mysql:
condition: service_healthy
mysql:
image: mysql:8.0
environment:
MYSQL_DATABASE: bitrix
MYSQL_USER: bitrix
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
volumes:
- mysql_data:/var/lib/mysql
- ./docker/mysql/my.cnf:/etc/mysql/conf.d/bitrix.cnf:ro
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 10s
timeout: 5s
retries: 5
memcached:
image: memcached:1.6-alpine
command: memcached -m 512 -I 32m
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.11.0
environment:
- discovery.type=single-node
- ES_JAVA_OPTS=-Xms512m -Xmx512m
- xpack.security.enabled=false
volumes:
- es_data:/usr/share/elasticsearch/data
volumes:
bitrix_files:
mysql_data:
es_data:
PHP-FPM Dockerfile
# docker/php/Dockerfile
FROM php:8.1-fpm-alpine
# Dependencies for extensions
RUN apk add --no-cache \
freetype-dev libjpeg-turbo-dev libpng-dev libwebp-dev \
libzip-dev libxml2-dev oniguruma-dev \
icu-dev libmemcached-dev zlib-dev
# PHP extensions required by 1C-Bitrix
RUN docker-php-ext-configure gd \
--with-freetype --with-jpeg --with-webp \
&& docker-php-ext-install -j$(nproc) \
gd mbstring opcache pdo_mysql mysqli \
xml zip intl bcmath exif
# Memcached via PECL
RUN pecl install memcached \
&& docker-php-ext-enable memcached
# Redis via PECL
RUN pecl install redis \
&& docker-php-ext-enable redis
# OPcache
RUN docker-php-ext-install opcache
WORKDIR /var/www/html
# Create a user with the same UID as the host
ARG UID=1000
RUN adduser -u $UID -D -S -G www-data bitrix
USER bitrix
PHP Configuration for 1C-Bitrix
; docker/php/php.ini
memory_limit = 256M
upload_max_filesize = 256M
post_max_size = 256M
max_execution_time = 90
; OPcache
opcache.enable = 1
opcache.memory_consumption = 128
opcache.max_accelerated_files = 10000
opcache.validate_timestamps = 1
opcache.revalidate_freq = 2
; Sessions via Memcached
session.save_handler = memcached
session.save_path = "memcached:11211"
Handling Stateful Files
1C-Bitrix stores in the filesystem: uploaded files (upload/), cache (bitrix/cache/), and configuration (.settings.php). Strategies:
Named volumes (as in docker-compose above) — data lives in a Docker volume, survives container recreation. Downside: transferring data between hosts requires volume backup.
Bind mounts for data, named volume for code:
volumes:
- ./src:/var/www/html:ro # code (read-only)
- uploads_data:/var/www/html/upload # uploads
- cache_data:/var/www/html/bitrix/cache # cache
S3 for upload — the most cloud-native approach. 1C-Bitrix supports S3-compatible storage via its module. Containers become truly stateless.
CI/CD with Docker
# .github/workflows/deploy.yml (excerpt)
deploy:
steps:
- name: Build PHP image
run: docker build -t registry.example.com/bitrix-php:${{ github.sha }} ./docker/php
- name: Push to registry
run: docker push registry.example.com/bitrix-php:${{ github.sha }}
- name: Deploy to production
run: |
ssh deploy@prod "
cd /opt/bitrix &&
docker-compose pull &&
docker-compose up -d --no-deps php-fpm nginx &&
docker-compose exec php-fpm php /var/www/html/bitrix/modules/main/cli/healthcheck.php
"
Production Specifics
Logs. Bitrix writes logs to files. In Docker, logs should go to stdout/stderr for collection via the Docker logging driver:
// /bitrix/php_interface/init.php
define('LOG_FILENAME', 'php://stderr');
Scheduled tasks (agents). Cron inside the container or as a separate container:
cron:
build: ./docker/php
volumes:
- bitrix_files:/var/www/html
command: crond -f -d 8
Debugging. Xdebug only in the development build:
# docker/php/Dockerfile.dev
FROM registry.example.com/bitrix-php:latest
RUN pecl install xdebug && docker-php-ext-enable xdebug
COPY xdebug.ini /usr/local/etc/php/conf.d/
Timeline
A basic Docker environment for development — 2–3 days. A production-ready configuration with CI/CD, monitoring, and S3 for files — 7–14 days.







