A WordPress website is a great way to get your own personal corner of the internet. But when you’re starting out, it can be difficult to set up a WordPress site on your own—especially if you’re not familiar with installing software and configurations. Docker lets you sidestep these obstacles by running WordPress as a container, so even if you don’t know how to install WordPress from scratch, Docker will take care of the heavy lifting for you. This guide will walk you through setting up a clean WordPress installation that’s up and running in no time!
What Exactly Is a Docker?
Docker is a piece of software that allows users to create and run applications in containers. A container is a virtual environment that isolates applications and their dependencies from each other. Docker uses an imaging model, meaning that you package your application as a tarball and then use the docker image command to create a container from that tarball.
The Benefits of Using WordPress With Docker
The advantages of using Docker are manifold: you can improve deployability, portability, and security by packaging your application as a container; you can reduce build time by using pre-made images, and you can integrate with existing systems more easily since you can use images from public repositories. By default, Docker is installed on Mac OS X, Windows, and Linux.
WordPress Docker Tutorial: How To Setup Your WordPress Site Using Docker
When using WordPress, you’ve probably been using it on a local web server. However, Docker is gaining in popularity and is becoming a more favorable option for hosting WordPress.
In this article, we’ll show you how to install and set up WordPress so that it works properly on your website with Docker.
Docker Desktop App:
First, you have to install and activate the Docker desktop app.
It is free, so you don’t need to worry.
Click the link below to access their download link.
When the installation is complete, the Docker icon will appear in the taskbar.
Set up WordPress in Docker
Step 1: Create a new folder
For creating folders on the terminal, type: mkdir WordPress && cd WordPress.
In this folder, create a file: docker-compose.yml
To define the version of the composition: version: ‘4.7
So we define services as: services: # Our services
Step 2: Create a Database
On the terminal, add this database
services:
db:
image: mariadb
volumes:
- db_data:/var/lib/mysql
restart: unless-stopped
ports:
- 3307:3306
environment:
MYSQL_ROOT_PASSWORD: rootpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
In order to store our database, I am utilizing the mariadb image and inserting data via mysql.
Port for mapping SQL client tool to open it.
Step 3: Attached the Database to themes and plugins
Type this on the terminal,
services:
db:
# All DB stuff (see above)
wordpress:
depends_on:
- db
image: wordpress:latest
volumes:
- wordpress_data:/var/www/html
ports:
- '8000:80'
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
It ensures it spools up correctly.
Here we use the port to host on port 8000.
Step 4: Create a volumes
Type this on the terminal,
volumes:
db_data: {}
wordpress_data: {}
Docker-compose up the folder’s instances. First time may take a minute.
The Docker Desktop app should look like this:
WordPress site runs on Docker:
Step 1: Localhost:8000
Open a browser and go to localhost:8000.
You’ll be greeted on the WordPress installation page with:
Select the language of your choice.
Step 2: Language Choose
Select the language of your choice, then click on Next Step.
Step 3: Login Into WordPress Admin Panel
After successfully login in with wp-admin, you will get a WordPress dashboard like the image below.
Hurrah! Your WordPress is set up in Docker.
Related Article
Final Words
In this WordPress Docker tutorial, we will be setting up a WordPress site using Docker. By following along, you’ll learn how to install and configure Docker on your computer, create a container for your WordPress site, and finally run the application inside the container.
This will give you a working environment for developing and testing your WordPress applications using Docker.
If you’re interested in learning more about Docker or want to explore some of its other use cases, be sure to check out our other tutorials on the subject!