Docker and containerization have revolutionized the way developers and system administrators deploy applications, streamlining setup, management, and scalability. When it comes to WordPress, using Docker alongside OpenLiteSpeed (OLS) creates a blazing-fast, lightweight, and easily portable deployment. In this comprehensive guide, you’ll learn how to set up WordPress using LiteSpeed’s one-click script, Dockerize it, and efficiently deploy it to any Ubuntu 22 LTS server.
Why Dockerize WordPress with OpenLiteSpeed?
Docker simplifies application deployment by bundling all the software dependencies into container images. Using OpenLiteSpeed with WordPress in Docker gives you:
- Rapid Deployment: Deploy WordPress in minutes on any environment.
- Consistency: Ensure consistency between development and production environments.
- Portability: Quickly transfer your setup across servers or cloud environments.
- Scalability: Effortlessly scale up resources and horizontally scale across clusters.
Step 1: Setup WordPress using OpenLiteSpeed’s One-Click Script on Ubuntu 22 LTS
We’ll begin by using LiteSpeed’s official one-click install script to quickly set up WordPress and OpenLiteSpeed.
Initial Ubuntu Preparation
Start by connecting to your Ubuntu 22 LTS server and updating it:
sudo apt update && sudo apt upgrade -y
Run LiteSpeed’s One-Click Installation
LiteSpeed provides a convenient one-liner to set up OpenLiteSpeed and WordPress. Run this command:
bash <( curl -sk https://raw.githubusercontent.com/litespeedtech/ls-cloud-image/master/Setup/wpimgsetup.sh )
The script automatically sets up:
- OpenLiteSpeed Web Server
- PHP (LSAPI) with optimized settings
- MariaDB/MySQL database
- WordPress CMS with recommended security practices
Follow the prompts provided by the script to finalize setup, noting your WordPress admin login details once provided.
Step 2: Dockerize the WordPress + OpenLiteSpeed Setup
Now that we have a fully functioning WordPress instance, the next step is to Dockerize this environment. We’ll create a Docker image that can be deployed quickly on other servers.
Install Docker on Ubuntu 22 LTS
Ensure Docker and Docker Compose are installed:
sudo apt install ca-certificates curl software-properties-common -y
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu jammy stable" | sudo tee /etc/apt/sources.list.d/docker.list
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
sudo usermod -aG docker $USER
newgrp docker
Prepare Dockerfile
Create a new directory called wp-ols-docker
and navigate into it:
mkdir ~/wp-ols-docker && cd ~/wp-ols-docker
Create a file named Dockerfile
with the following content:
FROM ubuntu:22.04
# Install dependencies
RUN apt update && apt install -y wget curl nano sudo git
# Install OpenLiteSpeed and dependencies
RUN bash <( curl -sk https://raw.githubusercontent.com/litespeedtech/ls-cloud-image/master/Setup/wpimgsetup.sh )
# Expose HTTP/HTTPS Ports
EXPOSE 80 443 7080
# Start OpenLiteSpeed service at container start
CMD ["/usr/local/lsws/bin/lswsctrl", "start", "&&", "tail", "-f", "/usr/local/lsws/logs/error.log"]
Note:
This Dockerfile leverages LiteSpeed’s automated setup to provision OpenLiteSpeed and WordPress within the container. Upon startup, it ensures the web server is running and logs are tailed for container persistence.
Step 3: Building and Testing the Docker Image
Build the Docker Image
From your Dockerfile directory, run the following command to build the Docker image:
docker build -t wp-openlitespeed .
Verify the Docker Image
Verify your image was built successfully:
docker images
You should see your new image (wp-openlitespeed
) listed.
Run the Docker Container
Launch the container to test it locally:
docker run -d -p 80:80 -p 7080:7080 --name wordpress-ols wp-openlitespeed
- Port
80
is for HTTP access to your WordPress site. - Port
7080
accesses the OLS admin panel (default credentials from setup script).
Check your WordPress site by navigating to your server’s IP or domain at:
http://<YOUR_IP>/
Step 4: Deploying your Dockerized WordPress to Another Server
Now, let’s export your Docker image to easily deploy it onto another Ubuntu 22 LTS server.
Export the Docker Image
First, export the Docker image on your original server:
docker save wp-openlitespeed > wp-openlitespeed.tar
Copy this tar file (wp-openlitespeed.tar
) securely to your destination server using SCP or SFTP.
Import and Run on Another Ubuntu 22 LTS Server
On the destination server, first install Docker (repeat Step 2 Docker installation above).
Next, load your Docker image into Docker’s local repository:
docker load < wp-openlitespeed.tar
Verify the image was imported correctly:
docker images
Run your container on the new server easily using:
docker run -d -p 80:80 -p 7080:7080 --name wordpress-ols wp-openlitespeed
Your WordPress site will immediately become available at:
http://<NEW_SERVER_IP>/
Step 5: Using Docker Compose for Easier Management (Optional)
For even easier management, consider creating a docker-compose.yml
file within your deployment directory:
Create docker-compose.yml:
version: '3'
services:
wordpress-ols:
image: wp-openlitespeed
container_name: wordpress-ols
restart: always
ports:
- "80:80"
- "7080:7080"
volumes:
- wordpress_data:/usr/local/lsws/wordpress
- db_data:/var/lib/mysql
volumes:
wordpress_data:
db_data:
Deploy Using Docker Compose
Run your container stack easily:
docker compose up -d
This method ensures easy start/stop/restart management and automatic restarts on system reboots.
Final Thoughts: Docker and WordPress Made Simple
By containerizing your WordPress environment with OpenLiteSpeed, deployment becomes rapid, consistent, and highly manageable. Dockerization simplifies updates, backups, and portability, freeing you from manual configurations and traditional deployment hurdles.
Embrace Docker to enhance your WordPress workflow—bringing scalability, efficiency, and ease to your projects!