Bringing up a WordPress web server in Docker for development

Sometimes, pure WordPress is required to test plugins, themes, and functional improvements. In this article, I will demonstrate how I deploy a working environment with a ready-made web server (Nginx + php-fpm + MariaDB) and the final WordPress release installed.


For work we need:

  • Virtualization software VirtualBox
  • Form CentOS 8.2 (7.2 Gb)
  • Hosting where we will upload our kickstart file to quickly install a pre-configured OS

Preparing a virtual machine

Launch VirtualBox and create a new virtual machine:

  • Name: wordpress
  • Type: Linux
  • Version: Red Hat (64-bit)
  • Memory capacity: 4096 Mb
  • Hard Drive: Create New
  • Hard Drive Type: VDI
  • Format: Dynamic
  • Size: 20 Gb

Add the downloaded image to the VirtualBox library to boot from it

Installing CentOS 8

I install Centos 8 from a kickstart file uploaded to the server beforehand. In this file I have already registered: user, password, certificate, list of preinstalled software

# vmlinuz initrd=initrd.img inst.ks=https://<your-server>/ks-centos8.cfg
# version=RHEL8
# System authorization information
auth --enableshadow --passalgo=sha512
# Install OS instead of upgrade
# Reboot after installation
reboot --eject
# License agreement
eula --agreed
# Use CDROM installation media
# Use text install
# Keyboard layouts
keyboard --vckeymap=ru --xlayouts="us",'ru' --switch="grp:alt_shift_toggle"
# System language
lang en_US.UTF-8 --addsupport=ru_RU.UTF-8

# Network information
# dhcp
#network  --bootproto=dhcp --device=link --ipv6=auto --activate
# static NAT
network --bootproto=static --device=link --gateway= --ip= --nameserver=, --netmask= --ipv6=auto --activate
# static brige
#network --bootproto=static --device=link --gateway= --ip= --nameserver= --netmask= --ipv6=auto --activate
network --hostname=localhost.localdomain

# Root password
rootpw --iscrypted $6$lZma0ZiWGD0yY4hW$.T/sRzouE5X.fghfghfghfghfgh/ODmBV7U1PvbcWmWM/7h6oZqkp.6eRDdy3x.YICI441BWk5QfVYDav7Z/
# Add user
user --groups=wheel --name=admin --iscrypted --password=$6$R9QSOFvUWKc816UF$cyXMFXtCSat1zPsqa806/dfgdfgdfgdfgTwVj1hV8nlFEXK2HrVg2C3kLTw38xPoGcy5193lhGxS7aJT/

# Add ssh user key
sshkey --username=root "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFCiz11YRaT3/C7QUVOJdfgdfgdfgdfgdfgdffg9k/+e94dYb ed25519-root"
sshkey --username=admin "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGv4Pt+Ocj3WEdfgdfgdfgdfgdfgdfgddffgdgdfgdfgdiEe ed25519-admin"

# Disable the Setup Agent on first boot
firstboot --disable
# Do not configure the X Window System
# System services
#services --disabled="chronyd"
# System timezone
timezone Europe/Moscow --isUtc --nontp

# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
# Partition clearing information
clearpart --all --initlabel --drives=sda
#clearpart --all --initlabel --drives=sda,sdb
# Disk partitioning information
part /boot --fstype="xfs" --ondisk=sda --size=512
part pv.1874 --fstype="lvmpv" --ondisk=sda --size=1 --grow
#part pv.7906 --fstype="lvmpv" --ondisk=sdb --size=1 --grow
volgroup centos --pesize=4096 pv.1874
#volgroup vg_docker --pesize=4096 pv.7906
logvol swap  --fstype="swap" --size=512 --name=swap --vgname=centos
#logvol /var  --fstype="xfs" --size=1024 --grow --name=var --vgname=centos
logvol /  --fstype="xfs" --size=1024 --grow --name=root --vgname=centos
#logvol /var/lib/docker  --fstype="xfs" --size=1024 --grow --name=lv_docker --vgname=vg_docker



%addon com_redhat_kdump --enable --reserve-mb='auto'


pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty

echo "admin ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/admin
dnf -y update
dnf -y install epel-release
dnf -y install wget tar zip unzip bzip2 traceroute net-tools nano bind-utils telnet htop atop iftop lsof git rsync policycoreutils-python-utils

In this file, you need to change the hash of passwords for root and admin users (having generated them in advance), as well as change the public part of user certificates

We start the created virtual machine, and select the attached image in the boot disk selection window

At the time of boot (when the boot disk menu appears), press ESC and enter:

                        vmlinuz initrd=initrd.img inst.ks=https://<your-server>/ks-centos8.cfg

In the process of installing the OS, right-click on the network settings icon and configure it

  • Connection type: NAT
  • Optional: Port Forwarding

Installing Docker and Docker-Compose

After installing and loading the OS, launch putty or kitty, connect to localhost: 22 and enter the commands in turn. Enter the commands without the $ sign

                        $ sudo dnf -y install -y yum-utils device-mapper-persistent-data lvm2
$ sudo dnf config-manager --add-repo=
$ sudo dnf -y install docker-ce --nobest
$ sudo usermod -aG docker $(whoami)
$ newgrp docker
$ sudo systemctl enable --now docker
                        $ sudo curl -L "$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose
$ sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
$ sudo firewall-cmd --zone=public --add-masquerade --permanent
$ sudo firewall-cmd --reload

Installing a Web Server and WordPress in Docker

Well, the final step, clone the repository, install docker / docker-compose and start the web server

                        $ git clone 
$ cd wordpress-nginx-docker
$ docker-compose up -d

Launch the browser, go to http: // localhost

Video for clarity:

Related Posts