How To Install WordPress On Docker in 2024
How To Install WordPress On Docker in 2024
TUTORIALS menu
Setting up an isolated environment for developing WordPress websites can initially seem challenging.
Luckily, containerization tools like Docker exist, which help to streamline the development, testing, and
deployment processes.
This tutorial will show you how to install and deploy a local WordPress site on a Docker container.
Additionally, we will touch on the best security and development practices for WordPress Docker containers.
What Is Docker?
How to Deploy WordPress Image as a Docker Container
1. Install Docker
2. Set Up a WordPress Container on Docker
3. Complete the WordPress Installation on a Web Browser
How to Secure WordPress Installation With Docker Secrets
Website Development on WordPress Docker Container
What Is Docker?
Docker is an open-source containerization software that creates isolated environments to run various
applications. Users can develop, test, and run multiple applications on the same physical and virtual servers.
Unlike virtual machines, each container does not require its own OS as it shares the host kernel. Thus, the
machine’s workload is much more lightweight, and such a server can run multiple containers simultaneously
without losing performance.
For example, Docker is highly useful for WordPress developers. A WordPress test environment usually uses
up a lot of system resources, while Docker allows developers to make a minimal environment without
wasting server space and memory.
https://www.hostinger.com/tutorials/run-docker-wordpress?utm_campaign=Generic-Tutorials-DSA|NT:Se|LO:Other-LATAM-t1-EN&utm_medium=ppc&gad_source=1&gclid=EAIaIQobChMIx8_flPXKhwMVzKhoCR12J… 1/17
7/28/24, 6:45 PM How to Install WordPress on Docker in 2024
1. Install Docker
Docker is available for Windows, macOS, and Ubuntu. Here’s how you can install it on any of the three
operating systems:
7. Lastly, install the latest version of Docker Engine, containerd, and Docker Compose.
8. To confirm that the installation process was successful, run the following command. The following
success message should appear:
https://www.hostinger.com/tutorials/run-docker-wordpress?utm_campaign=Generic-Tutorials-DSA|NT:Se|LO:Other-LATAM-t1-EN&utm_medium=ppc&gad_source=1&gclid=EAIaIQobChMIx8_flPXKhwMVzKhoCR12J… 2/17
7/28/24, 6:45 PM How to Install WordPress on Docker in 2024
TUTORIALS menu
Alternatively, consider using Hostinger’s VPS as your Docker host. It offers a pre-made template to speed
up the setup process – Ubuntu 22.04 64bit with Docker. If you have Hostinger VPS already, you can install
Docker with a few clicks:
https://www.hostinger.com/tutorials/run-docker-wordpress?utm_campaign=Generic-Tutorials-DSA|NT:Se|LO:Other-LATAM-t1-EN&utm_medium=ppc&gad_source=1&gclid=EAIaIQobChMIx8_flPXKhwMVzKhoCR12J… 3/17
7/28/24, 6:45 PM How to Install WordPress on Docker in 2024
TUTORIALS menu
4 GB of RAM
macOS version 10.15 or newer
No previous versions of VirtualBox 4.3.30 can be installed
https://www.hostinger.com/tutorials/run-docker-wordpress?utm_campaign=Generic-Tutorials-DSA|NT:Se|LO:Other-LATAM-t1-EN&utm_medium=ppc&gad_source=1&gclid=EAIaIQobChMIx8_flPXKhwMVzKhoCR12J… 4/17
7/28/24, 6:45 PM How to Install WordPress on Docker in 2024
2. Open your Applications folder and double-click docker.app. During the configuration process, you’ll
be asked to enter your password.
3. When prompted, Accept the service agreement; otherwise, the installation will fail.
https://www.hostinger.com/tutorials/run-docker-wordpress?utm_campaign=Generic-Tutorials-DSA|NT:Se|LO:Other-LATAM-t1-EN&utm_medium=ppc&gad_source=1&gclid=EAIaIQobChMIx8_flPXKhwMVzKhoCR12J… 5/17
7/28/24, 6:45 PM How to Install WordPress on Docker in 2024
TUTORIALS menu
4. Once the installation process is finished, you should see the Docker menu on your desktop’s status
bar.
4 GB of RAM
64-bit processor from 2010 or more recent
Virtualization enabled in BIOS
Linux kernel update package installed if you are using the WSL 2 Docker back-end
4. Once the installation is finished, click Close and restart and wait for your computer to reboot.
5. After reboot, Accept the service agreement, and Docker will be ready to use.
It’s worth noting that all required images are acquired from Docker Hub:
WordPress – the official WordPress Docker image. Includes all WordPress files, Apache server, and
PHP.
https://www.hostinger.com/tutorials/run-docker-wordpress?utm_campaign=Generic-Tutorials-DSA|NT:Se|LO:Other-LATAM-t1-EN&utm_medium=ppc&gad_source=1&gclid=EAIaIQobChMIx8_flPXKhwMVzKhoCR12J… 6/17
7/28/24, 6:45 PM How to Install WordPress on Docker in 2024
MySQL – required for MySQL root user, password, and database connection variables.
TUTORIALS
phpMyAdmin – a web application for managing databases. menu
1. Open your operating system’s preferred command line interface and check the Docker Compose
Installation version:
2. Create a new project directory for WordPress application with the following command:
mkdir wordpress
cd wordpress
4. Using your preferred text editor, create a new docker-compose.yml file, and paste the contents
below:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
version: "3"
# Defines which compose version to use
services:
# Services line define which Docker images to run. In this case, it will be MySQL server and WordPress image.
db:
image: mysql:5.7
# image: mysql:5.7 indicates the MySQL database container image from Docker Hub used in this installation.
restart: always
environment:
MYSQL_ROOT_PASSWORD: MyR00tMySQLPa$$5w0rD
MYSQL_DATABASE: MyWordPressDatabaseName
MYSQL_USER: MyWordPressUser
MYSQL_PASSWORD: Pa$$5w0rD
# Previous four lines define the main variables needed for the MySQL container to work: database, database username, database user password, and the
MySQL root password.
wordpress:
depends_on:
- db
image: wordpress:latest
restart: always
# Restart line controls the restart mode, meaning if the container stops running for any reason, it will restart the process immediately.
ports:
- "8000:80"
# The previous line defines the port that the WordPress container will use. After successful installation, the full path will look like this: http://localhost:8000
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: MyWordPressUser
WORDPRESS_DB_PASSWORD: Pa$$5w0rD
WORDPRESS_DB_NAME: MyWordPressDatabaseName
# Similar to MySQL image variables, the last four lines define the main variables needed for the WordPress container to work properly with the MySQL
container.
volumes:
["./:/var/www/html"]
volumes:
mysql: {}
version: "3" # Defines which compose version to use services: # Services line define which Docker images to run. In this case, it will be MySQL server and
WordPress image. db: image: mysql:5.7 # image: mysql:5.7 indicates the MySQL database container image from Docker Hub used in this installation. restart:
always environment: MYSQL_ROOT_PASSWORD: MyR00tMySQLPa$$5w0rD MYSQL_DATABASE: MyWordPressDatabaseName MYSQL_USER:
MyWordPressUser MYSQL_PASSWORD: Pa$$5w0rD # Previous four lines define the main variables needed for the MySQL container to work: database,
database username, database user password, and the MySQL root password. wordpress: depends_on: - db image: wordpress:latest restart: always # Restart
line controls the restart mode, meaning if the container stops running for any reason, it will restart the process immediately. ports: - "8000:80" # The previous
line defines the port that the WordPress container will use. After successful installation, the full path will look like this: http://localhost:8000 environment:
WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_USER: MyWordPressUser WORDPRESS_DB_PASSWORD: Pa$$5w0rD WORDPRESS_DB_NAME:
MyWordPressDatabaseName # Similar to MySQL image variables, the last four lines define the main variables needed for the WordPress container to work
properly with the MySQL container. volumes: ["./:/var/www/html"] volumes: mysql: {}
https://www.hostinger.com/tutorials/run-docker-wordpress?utm_campaign=Generic-Tutorials-DSA|NT:Se|LO:Other-LATAM-t1-EN&utm_medium=ppc&gad_source=1&gclid=EAIaIQobChMIx8_flPXKhwMVzKhoCR12J… 7/17
7/28/24, 6:45 PM How to Install WordPress on Docker in 2024
version: "3"
# TUTORIALS
Defines which compose version to use menu
services:
# Services line define which Docker images to run. In this case, it will be MySQL
server and WordPress image.
db:
image: mysql:5.7
# image: mysql:5.7 indicates the MySQL database container image from Docker Hub used
in this installation.
restart: always
environment:
MYSQL_ROOT_PASSWORD: MyR00tMySQLPa$$5w0rD
MYSQL_DATABASE: MyWordPressDatabaseName
MYSQL_USER: MyWordPressUser
MYSQL_PASSWORD: Pa$$5w0rD
# Previous four lines define the main variables needed for the MySQL container to
work: database, database username, database user password, and the MySQL root password.
wordpress:
depends_on:
- db
image: wordpress:latest
restart: always
# Restart line controls the restart mode, meaning if the container stops running for
any reason, it will restart the process immediately.
ports:
- "8000:80"
# The previous line defines the port that the WordPress container will use. After
successful installation, the full path will look like this: http://localhost:8000
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: MyWordPressUser
WORDPRESS_DB_PASSWORD: Pa$$5w0rD
WORDPRESS_DB_NAME: MyWordPressDatabaseName
# Similar to MySQL image variables, the last four lines define the main variables needed
for the WordPress container to work properly with the MySQL container.
volumes:
["./:/var/www/html"]
volumes:
mysql: {}
5. With the Docker Compose file created, run the following command in the same wordpress directory
to create and start the containers:
docker compose up -d
WordPress installation window asking the user to choose the default language
Important! Ensure you are not running any other content management system or service on the
same 8000 port. Otherwise, it won’t work properly.
https://www.hostinger.com/tutorials/run-docker-wordpress?utm_campaign=Generic-Tutorials-DSA|NT:Se|LO:Other-LATAM-t1-EN&utm_medium=ppc&gad_source=1&gclid=EAIaIQobChMIx8_flPXKhwMVzKhoCR12J… 8/17
7/28/24, 6:45 PM How to Install WordPress on Docker in 2024
TUTORIALS menu
When a Success! message pops-up, log in using your newly created details.
https://www.hostinger.com/tutorials/run-docker-wordpress?utm_campaign=Generic-Tutorials-DSA|NT:Se|LO:Other-LATAM-t1-EN&utm_medium=ppc&gad_source=1&gclid=EAIaIQobChMIx8_flPXKhwMVzKhoCR12J… 9/17
7/28/24, 6:45 PM How to Install WordPress on Docker in 2024
TUTORIALS menu
Setting up phpMyAdmin
phpMyAdmin is a great tool for viewing and managing any existing databases. All you need to do is include
these lines to an existing .yml file just after the services line along with the MySQL database service:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
version: "3"
services:
db:
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: MyR00tMySQLPa$$5w0rD
MYSQL_DATABASE: MyWordPressDatabaseName
MYSQL_USER: MyWordPressUser
MYSQL_PASSWORD: Pa$$5w0rD
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
restart: always
environment:
PMA_HOST: db
PMA_USER: MyWordPressUser
PMA_PASSWORD: Pa$$5w0rD
ports:
- "8080:80"
version: "3" services: db: image: mysql:5.7 restart: always environment: MYSQL_ROOT_PASSWORD: MyR00tMySQLPa$$5w0rD MYSQL_DATABASE:
MyWordPressDatabaseName MYSQL_USER: MyWordPressUser MYSQL_PASSWORD: Pa$$5w0rD phpmyadmin: image: phpmyadmin/phpmyadmin:latest
restart: always environment: PMA_HOST: db PMA_USER: MyWordPressUser PMA_PASSWORD: Pa$$5w0rD ports: - "8080:80"
version: "3"
services:
db:
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: MyR00tMySQLPa$$5w0rD
MYSQL_DATABASE: MyWordPressDatabaseName
MYSQL_USER: MyWordPressUser
MYSQL_PASSWORD: Pa$$5w0rD
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
restart: always
environment:
PMA_HOST: db
PMA_USER: MyWordPressUser
PMA_PASSWORD: Pa$$5w0rD
ports:
- "8080:80"
docker compose up -d
Once done, open http://localhost:8080/, and you’ll be able to see the phpMyAdmin interface along with your
WordPress database.
https://www.hostinger.com/tutorials/run-docker-wordpress?utm_campaign=Generic-Tutorials-DSA|NT:Se|LO:Other-LATAM-t1-EN&utm_medium=ppc&gad_source=1&gclid=EAIaIQobChMIx8_flPXKhwMVzKhoCR1… 10/17
7/28/24, 6:45 PM How to Install WordPress on Docker in 2024
TUTORIALS menu
Pro Tip
We recommend double-checking for images that you no longer use, then
removing Docker images and other unnecessary files.
In this tutorial, we will use Docker secrets to mask our WORDPRESS_DB_PASSWORD variable. WordPress
will get the database password from a secret file we shall provide ourselves. Here’s an example:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
wordpress:
depends_on:
- db
image: wordpress:latest
restart: always
ports:
- "8000:80"
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: MyWordPressUser
WORDPRESS_DB_PASSWORD_FILE: /run/secrets/wordpress_password
WORDPRESS_DB_NAME: MyWordPressDatabaseName
secrets:
- wordpress_password
secrets:
wordpress_password:
file: ./wordpress_password.txt
wordpress: depends_on: - db image: wordpress:latest restart: always ports: - "8000:80" environment: WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: MyWordPressUser WORDPRESS_DB_PASSWORD_FILE: /run/secrets/wordpress_password WORDPRESS_DB_NAME:
MyWordPressDatabaseName secrets: - wordpress_password secrets: wordpress_password: file: ./wordpress_password.txt
https://www.hostinger.com/tutorials/run-docker-wordpress?utm_campaign=Generic-Tutorials-DSA|NT:Se|LO:Other-LATAM-t1-EN&utm_medium=ppc&gad_source=1&gclid=EAIaIQobChMIx8_flPXKhwMVzKhoCR12… 11/17
7/28/24, 6:45 PM How to Install WordPress on Docker in 2024
wordpress:
TUTORIALS
depends_on: menu
- db
image: wordpress:latest
restart: always
ports:
- "8000:80"
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: MyWordPressUser
WORDPRESS_DB_PASSWORD_FILE: /run/secrets/wordpress_password
WORDPRESS_DB_NAME: MyWordPressDatabaseName
t
Related tutorials
How to Host a dedicated Terraria server using Hostinger Game Panel and manual configuration
A dedicated Terraria server gives you more flexibility and customization options that make the gameplay more interesting. For
example, you can install...
By Aris Sentika
https://www.hostinger.com/tutorials/run-docker-wordpress?utm_campaign=Generic-Tutorials-DSA|NT:Se|LO:Other-LATAM-t1-EN&utm_medium=ppc&gad_source=1&gclid=EAIaIQobChMIx8_flPXKhwMVzKhoCR1… 12/17
7/28/24, 6:45 PM How to Install WordPress on Docker in 2024
TUTORIALS menu
Excellent
Frederick
June 29 2017 REPLY
Great tutorial. Thanks for putting this out there. Once someone is finished developing their wordpress based site, do you provide
the container to a host or export the wordpress and associated database in the traditional sense? Maybe I'm picturing this
inaccurately, but I'm assuming you shove the docker container into a slot on some docker compliant host and it just runs from
there. Any guidance appreciated! Thanks.
Kenji
September 10 2019 REPLY
Great tutorial. Really helped me getting my first babysteps towards Docker. Two things that aren't mentioned and took some
time for me to figure out, since newer versions are out. I got an error when I tried to run "docker-compose up -d" >> ERROR:
client version 1.22 is too old. Minimum supported API version is 1.24, please upgrade your client to a newer version This one is
https://www.hostinger.com/tutorials/run-docker-wordpress?utm_campaign=Generic-Tutorials-DSA|NT:Se|LO:Other-LATAM-t1-EN&utm_medium=ppc&gad_source=1&gclid=EAIaIQobChMIx8_flPXKhwMVzKhoCR1… 13/17
7/28/24, 6:45 PM How to Install WordPress on Docker in 2024
very simple to solve: Open the yml file and change the version from 2 to 2.1 >> Pulling from library/php no matching manifest for
windows/amd64 in the manifest list entries Also very simple to solve: 1 Right click Docker instance 2 Go to Settings 3 Daemonmenu
TUTORIALS 4
Advanced 5 Set the "experimental": true 6 Restart Docker
Domantas G.
September 24 2019
Bernd
November 22 2019 REPLY
just followed this tutorial on my Mac (10.15) and I cannot believe how simple this is. It just works! Great!!
Mohammedsohil
April 24 2021 REPLY
Hey, Domantas G. Thanks to you I am able to set up WordPress using docker. thanks a lot
Zat
September 14 2021 REPLY
If you're running this on Linux you have use "sudo docker-compose up-d" or you will receive an error message about
http+docker://localhost not runnning.
Sam
December 19 2021 REPLY
Excellent tutorial, I was stuck at a place as I was working with docker for one of my clients, and this article completely helped me
in satisfying the cleint. Thank you so much Domantas, Kudos!
Vakarė
December 22 2021
Mike Ritchie
January 02 2022 REPLY
Thanks, this worked amazingly well, and quickly! One thing though, I don't know where the active `wp_content` folder is. How do
I develop themes and plugins in this?
Vakarė
January 04 2022
Hi Mike, generally your wp-content will be right next to wp-admin and wp-includes folder. You can use find command on
Linux or Mac to find the location of your folder! Here's how to use the find command :)
https://www.hostinger.com/tutorials/run-docker-wordpress?utm_campaign=Generic-Tutorials-DSA|NT:Se|LO:Other-LATAM-t1-EN&utm_medium=ppc&gad_source=1&gclid=EAIaIQobChMIx8_flPXKhwMVzKhoCR1… 14/17
7/28/24, 6:45 PM How to Install WordPress on Docker in 2024
Vakarė
March 29 2022
Hi there! It looks like you might have a problem with either of these things: (1) you haven't created a database yet; (2) your
database credentials on your wp-config.php file are incorrect; (3) you're reaching the memory limit of your server. I'd suggest
to start by checking them :)
Klino
March 30 2022
thanks
jptiger
June 22 2022
Same here. I see the comment below saying that I haven't created a database. How do you do this? It might be helpful to
include those steps in the instructions
domantaspocius
July 01 2022
Hey there! Thanks for the feedback! You can setup a database inside Docker by checking out this resource! ?
Acal
August 21 2022 REPLY
Where can the WordPress files be found so that I can customize themes and plugins? Since I have numerous wordpress installs
on this computer it is not a simple search. Thanks!
domantaspocius
August 25 2022
Hey! The installation folder of WordPress will be located in your website's public_html folder. You can access it through a File
Manager or FTP client depending on where your websites are hosted ?
Brandon
May 06 2023 REPLY
I spent several hours debugging issues on this because WordPress would properly escape the special characters in the
passwords but my database client and the mysql command line did not do this automatically. I ended up changing the
password to "password" and it worked for me. However Docker also keeps the original username and password unless you
delete the volume used. the combination of WordPress not having issues and not knowing that the volume had the old
username and password caused a lot of grief. hopefully this comment can help someone avoid that in the future.
https://www.hostinger.com/tutorials/run-docker-wordpress?utm_campaign=Generic-Tutorials-DSA|NT:Se|LO:Other-LATAM-t1-EN&utm_medium=ppc&gad_source=1&gclid=EAIaIQobChMIx8_flPXKhwMVzKhoCR1… 15/17
7/28/24, 6:45 PM How to Install WordPress on Docker in 2024
TUTORIALS
Ignas R. menu
May 12 2023
Leave a reply
Comment*
Name*
Email*
By using this form you agree that your personal data would be processed in accordance with our Privacy Policy.
Submit
We are a web hosting provider on a mission to bring success to everyone who goes online. We do it by constantly improving server technology,
providing professional support, and making the web hosting experience seamless.
And More
HOSTING
Web Hosting
VPS Hosting
Cloud Hosting
WordPress Hosting
Email Hosting
CMS Hosting
Ecommerce Hosting
cPanel Hosting
https://www.hostinger.com/tutorials/run-docker-wordpress?utm_campaign=Generic-Tutorials-DSA|NT:Se|LO:Other-LATAM-t1-EN&utm_medium=ppc&gad_source=1&gclid=EAIaIQobChMIx8_flPXKhwMVzKhoCR1… 16/17
7/28/24, 6:45 PM How to Install WordPress on Docker in 2024
Online Stores
DOMAINS
Domain Checker
Domain Transfer
Free Domain
XYZ Domain
99 Cent Domains
WHOIS Checker
HELP
Tutorials
Knowledge Base
Report Abuse
INFORMATION
Server Status
Affiliate Program
Payment Methods
Wall of Fame
Reviews
Pricing
COMPANY
About Hostinger
Our Technology
Career
Contact Us
Blog
LEGAL
Privacy Policy
Terms of Service
© 2004-2024 hostinger.com - Premium Web Hosting, Cloud, VPS & Domain Registration Services.
https://www.hostinger.com/tutorials/run-docker-wordpress?utm_campaign=Generic-Tutorials-DSA|NT:Se|LO:Other-LATAM-t1-EN&utm_medium=ppc&gad_source=1&gclid=EAIaIQobChMIx8_flPXKhwMVzKhoCR1… 17/17