The wodpress image is based on the php image. So if we need any PHP extensions we should install it the same way
as
we do it for php images.
WordPress with a database:
version: '2.4'
services:
wordpress:
container_name: project.wp
image: wordpress
ports:
- "80:80"
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
WORDPRESS_DEBUG: 1
WORDPRESS_CONFIG_EXTRA: |
define( 'FS_METHOD', 'direct' );
depends_on:
- db
volumes:
- ./volumes/wordpress:/var/www/html
db:
container_name: project.db
image: mysql:5.7
environment:
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
MYSQL_RANDOM_ROOT_PASSWORD: '1'
volumes:
- ./volumes/db:/var/lib/mysql
phpmyadmin:
container_name: project.phpmyadmin
image: phpmyadmin
ports:
- "81:80"
environment:
- PMA_HOST=db
- PMA_USER=wordpress
- PMA_PASSWORD=wordpress
depends_on:
- db
We can choose a specific WP version (wordpress:php7.4-apache, for example).
Adding Xdebug
Dockerfile:
FROM wordpress
RUN pecl install "xdebug" \
&& docker-php-ext-enable xdebug
RUN echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/xdebug.ini && \
echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/xdebug.ini && \
echo "xdebug.client_host=192.168.1.13" >> /usr/local/etc/php/conf.d/xdebug.ini
Another option for installing xdebug:
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
RUN install-php-extensions xdebug
Changing PHP parameters
# Use the default production configuration
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
# Modify PHP settings using sed
# max_execution_time - This sets the maximum time in seconds a script is allowed to run before it is terminated by the parser.
# max_input_time - This sets the maximum time in seconds a script is allowed to parse input data, like POST and GET.
# post_max_size - Sets max size of post data allowed. This setting also affects file upload.
# memory_limit - This sets the maximum amount of memory in bytes that a script is allowed to allocate.
RUN sed -i 's/upload_max_filesize = .*/upload_max_filesize = 8192M/' /usr/local/etc/php/php.ini && \
sed -i 's/max_input_time = .*/max_input_time = -1/' /usr/local/etc/php/php.ini && \
sed -i 's/memory_limit = .*/memory_limit = -1/' /usr/local/etc/php/php.ini && \
sed -i 's/post_max_size = .*/post_max_size = 8192M/' /usr/local/etc/php/php.ini && \
sed -i 's/max_execution_time = .*/max_execution_time = 86400/' /usr/local/etc/php/php.ini
Deploy as a Swarm stack
WordPress and MySQL with Docker secrets and overlay networks:
version: '3.1'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
networks:
mysql_internal:
aliases: ["db"]
environment:
MYSQL_ROOT_PASSWORD_FILE: /run/secrets/db_root_password
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD_FILE: /run/secrets/db_password
secrets:
- db_root_password
- db_password
wordpress:
depends_on:
- db
image: wordpress:latest
networks:
mysql_internal:
aliases: ["wordpress"]
wordpress_public:
ports:
- "8001:80"
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD_FILE: /run/secrets/db_password
secrets:
- db_password
secrets:
db_password:
file: db_password.txt
db_root_password:
file: db_root_password.txt
volumes:
db_data:
networks:
mysql_internal:
driver: "overlay"
internal: true
wordpress_public:
driver: "overlay"
Deploy:
docker stack deploy --compose-file docker-compose.yml wp
See Swarm for cluster concepts.
Andrew Dorokhov