Docker is a software that enables the use and creation of Containers. Containers can be used to deploy WordPress. Here, we will discuss the benefits of using Docker and how you can install WordPress with Docker.
Let’s get started.
The Benefits of Using Docker
To set up WordPress, you need a proper stack; it may be LAMP (Linux, Apache, MySQL, PHP) or LEMP (Linux, Nginx, MySQL, PHP). Installing all these components can be time-consuming and you may not have the flexibility to play with your code. This is where Docker comes in.
Docker uses containers to create, deploy, and run applications. Each container supports a self-contained environment where you can set up your stack, libraries, and dependencies. Different containers can have different environments. Thus, you can install WordPress with Apache in one container and Nginx on another. You can turn on or turn off a container if you wish. With tools like Docker Compose, you can run multi-container applications.
You just need 2 containers and a Docker compose file to have your own WordPress installation.
How to install WordPress with Docker
You need to have Docker, Docker-Compose and a docker-compose.yml file on your server. Follow these steps to install WordPress with Docker:
Step 1: Install Docker Using the Official Repository
If you are installing Docker for the first time, you need to follow all these steps to set up the Docker Repository. After that, you will be able to update Docker from the repository.
If you have already set up the Docker repository, then you just need to perform step no. 5 and 6 to install Docker.
- Update the apt package index:
2. Install packages to allow apt to use a repository over HTTPS:
$ sudo apt-get install \
3. Add Docker’s official GPG Key:
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
4. Use the following command to set up the stable repository:
$ sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
5. Update the apt package index.
6. Install the latest version of Docker CE and containerd
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
Step 3: Install Docker-Compose
This is how you can install Docker-Compose:
- Run this command to download the current stable release of Docker Compose:
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
2. Apply executable permissions to the binary:
sudo chmod +x /usr/local/bin/docker-compose
Step 3: Create a docker-compose.yml File
To install WordPress we need two containers; one for WordPress and other for Database. These two can be set up using a single docker-compose.yml file that contains the following:
Step 4: Get Docker-Compose ready
- Move the docker-compose.yml file to a file location that you can conveniently access.
An example would be ~wordpress/docker-compose.yml
2. From the directory where you just put the docker-compose.yml file, run the following command:
Step 5: Get started with WordPress
Your WordPress is now installed and ready to be set up. You can visit the setup page by visiting the IP address of your server.
So this is how you can install WordPress with Docker. You can always refer to Docker’s official documentation for prerequisites. If you have any queries do leave us a comment.