Setup wordpress docker compose. Docker Compose is used to create and execute multi-container applications. Using these two technologies together can offer a quick and easy approach to install and manage a WordPress site.
In this article, we will show you how to use Docker Compose to set up a WordPress site in a matter of minutes. We will cover the following steps:
Table of Contents
Let’s get started!
wordpress docker compose

create a .docker folder in root directory
Next create app folder in .docker directory & create new two file Dockerfile , php-fpm.ini
in example-app/.docker/app/Dockerfile
Dockerfile will set the base image and specify the necessary commands and instructions to build the laravel application image. Add the following code to the file:
Dockerfile:
FROM php:8.0.2-fpm
ARG user
ARG uid
#Install Depedencies
RUN apt-get update && apt-get install -y git curl libpng-dev libonig-dev libxml2-dev zip unzip
# Clear Cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install PHP extensions
RUN docker-php-ext-install mysqli pdo pdo_mysql && docker-php-ext-enable pdo pdo_mysql
# Create system user to run Composer and Artisan Commands
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
chown -R $user:$user /home/$user
# Set working directory
WORKDIR /var/www/html
USER $user
Config PHP
in example-app/.docker/app/php-fpm.ini
date.timezone = UTC
display_errors = Off
log_errors = On
memory_limit = -1
max_execution_time = 3000
max_input_time = 600
memory_limit = 512M
post_max_size = 256M
upload_max_filesize = 256M
[opcache]
opcache.enable = 1
opcache.enable_cli = 1
opcache.revalidate_freq = 0
opcache.validate_timestamps = 1
opcache.max_accelerated_files = 25000
opcache.memory_consumption = 192
opcache.max_wasted_percentage = 10
opcache.interned_strings_buffer = 16
opcache.fast_shutdown = 1
realpath_cache_size = 4096K
realpath_cache_ttl = 7200
[xdebug]
xdebug.remote_enable = 1
xdebug.remote_port = 9000
xdebug.remote_autostart = 0
xdebug.remote_connect_back = 0
xdebug.idekey = PHPSTORM
Setup nginx config
create nginx folder in .docker folder & create default.conf file
example-app/.docker/nginx/default.conf
server { listen 80; index index.php index.html; error_log /var/log/nginx/error.log; access_log /var/log/nginx/access.log; root /var/www/html; location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass app:9000; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; } location / { try_files $uri $uri/ /index.php?$query_string; gzip_static on; } location = /.env { deny all; return 301 /; } location = /docker-compose.yml { deny all; return 301 /; } location ~* \.(git|rb|inc|yml|env)$ { deny all; return 301 /; } }
Creating docker-compose.yml for WordPress
docker-compose file will config app , nginx, phpmyadmin
version: "3.7" services: nginx: image: nginx:alpine container_name: example-nginx restart: unless-stopped ports: - 8000:80 volumes: - ./:/var/www/html:cached - ./.docker/nginx:/etc/nginx/conf.d networks: - example-network depends_on: - app app: build: args: user: Ridoy uid: 1000 context: ./.docker/app dockerfile: Dockerfile image: example container_name: example-app restart: unless-stopped working_dir: /var/www/html volumes: - ./:/var/www/html:cached - ./.docker/app/php-fpm.ini:/usr/local/etc/php/conf.d/99-app.ini networks: - example-network depends_on: - database database: image: mariadb:10.5.8 container_name: example-mariadb restart: unless-stopped ports: - 3308:3304 volumes: - example-volume:/var/lib/mysql environment: - MYSQL_ROOT_PASSWORD=${DB_PASSWORD} - MYSQL_USER=${DB_USERNAME} - MYSQL_PASSWORD=${DB_PASSWORD} - MYSQL_DATABASE=${DB_DATABASE} networks: - example-network phpmyadmin: image: phpmyadmin/phpmyadmin container_name: example-phpmyadmin restart: unless-stopped tty: true depends_on: - database ports: - 8081:80 environment: PMA_HOST: database MYSQL_ROOT_PASSWORD: ${DB_PASSWORD} networks: - example-network networks: example-network: driver: bridge volumes: example-volume: driver: local
Setup Environment ENV
DB_CONNECTION=mysql DB_HOST=database DB_PORT=3306 DB_DATABASE=example DB_USERNAME=root DB_PASSWORD=root
You just need to a single command to start all of the containers, create the volumes, and set up nginx,phpmyadmin and connect the networks
sudo docker-compose up --build
or
sudo docker-compose up -d --build
when docker build complete visit
visit http://127.0.0.1:8000
docker compose create a database for access phpmyadmin visit
visit http://127.0.0.1:8081
login with your DB_USERNAME & DB_PASSWORD which you set in env
for access bash use container name following command:
sudo docker exec -it example-app bash
Read More About Setup Laravel Project with Docker Nginx & phpMyadmin