Use WP-CLI when you want fast, scriptable WordPress installation on a server; use Docker when you need repeatable environments across laptops, staging, and production. For many professional teams, the best answer is not one or the other. It is Docker for the runtime and WP-CLI for WordPress tasks inside that runtime.
TLDR: WP-CLI is usually faster for installing WordPress directly on a prepared server, often cutting a manual 10-minute setup to under 2 minutes. Docker is stronger when a team needs the same PHP, database, and web server setup everywhere. For example, an agency deploying 12 client sites per month may save 6 to 10 hours by using Docker templates plus WP-CLI install scripts. If you manage one VPS, WP-CLI may be enough; if you manage many environments, Docker pays off quickly.
Contents
What WP-CLI actually does
WP-CLI is the official command-line tool for WordPress. It does not replace your web server, PHP, or database. Instead, it controls WordPress itself.
With WP-CLI, you can download WordPress, create a configuration file, run the installer, install plugins, activate themes, create users, flush caches, and run database operations. It is direct, scriptable, and easy to audit.
- Download core:
wp core download - Create config:
wp config create - Install WordPress:
wp core install - Install plugins:
wp plugin install contact-form-7 --activate - Update everything:
wp core update && wp plugin update --all
This is ideal for a VPS, a dedicated server, or a managed host that gives shell access. The workflow is clean. You prepare the server once, then run repeatable commands for each website.
What Docker actually does
Docker packages an application stack into containers. A typical WordPress Docker setup includes at least two containers: one for WordPress and one for MySQL or MariaDB. Some setups also add Nginx, Redis, phpMyAdmin, Mailpit, or a reverse proxy.
Docker does not install WordPress in the same sense as WP-CLI. It defines the operating environment. The container says, in effect, “run this PHP version, with these extensions, connected to this database, using this volume.”
That matters when several developers touch the same project. It drives me crazy when a site works on one laptop but fails on another because one person has PHP 8.1 and another has PHP 8.3. Docker reduces that mess.
A basic Docker Compose setup can start WordPress and a database with one command:
docker compose up -d
From there, you can either complete the web installer in a browser or run WP-CLI inside a container. That second option is usually better for professional deployment.
WP-CLI vs Docker: the real difference
The key distinction is simple. WP-CLI manages WordPress. Docker manages the environment WordPress runs in.
That means comparing them as direct rivals is slightly unfair. They solve different problems. Still, when people ask how to install WordPress from the command line, they usually want to know which path is safer, faster, and easier to maintain.
| Category | WP-CLI | Docker |
|---|---|---|
| Best for | Server setup, automation, WordPress maintenance | Consistent local, staging, and production environments |
| Speed | Very fast after server is ready | Fast after images and volumes are configured |
| Complexity | Low to moderate | Moderate to high |
| Portability | Depends on server setup | Strong across machines |
| Production fit | Excellent | Excellent when supported by proper hosting practice |
Installing WordPress with WP-CLI
A normal WP-CLI install is short. First, create the database. Then download WordPress and run the installer.
mkdir example-site
cd example-site
wp core download
wp config create \
--dbname=example_db \
--dbuser=example_user \
--dbpass='strong_password' \
--dbhost=localhost
wp core install \
--url="https://example.com" \
--title="Example Site" \
--admin_user="adminuser" \
--admin_password="another_strong_password" \
--admin_email="admin@example.com"
After that, you can add plugins, themes, and settings:
wp plugin install wordpress-seo --activate
wp theme install twentytwentyfour --activate
wp option update timezone_string "Europe/London"
This is where WP-CLI shines. It is direct and readable. A senior engineer can review a shell script and understand exactly what will happen. That is harder with a pile of manual browser clicks.
Deploying WordPress with Docker
A Docker setup normally starts with a docker-compose.yml file. It defines services, ports, volumes, credentials, and dependencies.
services:
wordpress:
image: wordpress:php8.2-apache
ports:
- "8080:80"
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_NAME: wordpress
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: password
volumes:
- ./wp-content:/var/www/html/wp-content
depends_on:
- db
db:
image: mariadb:10.11
environment:
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: rootpassword
volumes:
- db_data:/var/lib/mysql
volumes:
db_data:
Run it with:
docker compose up -d
Then install WordPress with WP-CLI inside the container, if the image includes it or if you add a WP-CLI service. This gives you a repeatable setup and a scriptable install. That combination is powerful.
Where WP-CLI is the better choice
Choose WP-CLI first when your server stack is already settled. For example, you may have Ubuntu, Nginx, PHP-FPM, MariaDB, SSL, backups, and monitoring already in place. In that case, Docker may add extra parts without enough benefit.
WP-CLI is also a good fit for small teams, solo developers, and agencies that use traditional hosting. It works well in cron jobs and deployment scripts. It is especially useful for updates, search-replace operations, and database exports.
- Best case: repeatable installs on known servers.
- Main risk: configuration drift between servers.
- Common annoyance: hosts that block shell access or limit permissions.
Where Docker is the better choice
Choose Docker when consistency matters more than raw simplicity. If developers, QA staff, and deployment systems all need the same stack, Docker is usually worth the setup time.
Honestly, it feels like Docker adds too much ceremony for a single brochure site. But for a WooCommerce project with custom plugins, Redis caching, a search service, and several developers, the extra structure prevents painful surprises.
- Best case: teams working across local, staging, and production.
- Main risk: poorly maintained images and weak volume planning.
- Common annoyance: permission issues that take 20 minutes to fix for a 30-second change.
The practical recommendation
For serious WordPress deployment, use both tools with clear roles. Let Docker define PHP, the database, web server behavior, and local development. Let WP-CLI install WordPress, configure options, manage plugins, and run maintenance tasks.
A clean workflow may look like this:
- Create a Docker Compose file for WordPress and MariaDB.
- Start the stack with
docker compose up -d. - Run WP-CLI inside the WordPress container.
- Install core, plugins, theme, and baseline settings from a script.
- Commit configuration files, not passwords or database dumps.
- Use separate secrets for local, staging, and production.
Security and maintenance concerns
Neither tool makes WordPress secure by itself. You still need strong passwords, least-privilege database users, file permission checks, updates, backups, and logging.
With WP-CLI, be careful with shell history. Do not leave admin passwords sitting in plain command logs. Use environment variables or secure secret handling where possible.
With Docker, avoid running old images for months. Pin versions when stability matters, but schedule image reviews. Also check mounted volumes carefully. A bad volume path can expose files or wipe expected content.
Final verdict
WP-CLI is the fastest route to install WordPress from the command line on a ready server. Docker is the better system for repeatable environments. If you want dependable deployment, do not treat them as enemies. Use Docker to standardize the stack, then use WP-CLI to make WordPress installation and maintenance predictable.
For one site on one server, start with WP-CLI. For teams, client work, staging pipelines, or complex builds, add Docker. The result is less guessing, fewer broken installs, and a deployment process people can actually trust.