arrow_back
Back

WordPress Docker image: official image and wp-cli usage

Andrew Dorokhov Andrew Dorokhov schedule 2 min read
menu_book Table of Contents

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
code

Need Help with Development?

Happy to help — reach out via the contacts or go straight to my Upwork profile.

work View Upwork Profile arrow_forward
Next Article

Node.js Docker image: official Node runtime and versions

arrow_forward