Warden and Docker: a local WordPress environment step by step
How to install WordPress locally in Docker with the Warden CLI: installing Docker and Warden, the .env file, the certificate, the hosts file and the database settings.
Docker
We will show how to install WordPress in Docker with the Warden CLI tool. Warden prepares many parts of the project environment for us, so someone who does not know Docker well can still get a local WordPress installation running quickly.
The tool runs on Linux and macOS. It was not supported on Windows when we wrote this article. Check the Warden documentation to see whether current versions support Windows (through WSL2).
The screenshots show the Polish admin interface; field names in the code stay as shown.
For an introduction to Docker, see the previous article: Installing WordPress and Docker with your own local domain.
Requirements
- Linux or macOS. The article describes Linux Ubuntu 20.04.1 LTS.
- Docker and Docker Compose.
- Administrator rights (
sudo), needed among other things to edit/etc/hosts.
Note: the installation commands and the version requirements of Warden change over time. Current information is in the Warden documentation.
Installing the Warden CLI on Linux Ubuntu
We work on Linux Ubuntu 20.04.1 LTS. First we prepare the system and install Docker and Warden.
Installing Docker
To install Docker, we use this command:
sudo snap install docker
Note: the snap package is the simplest option. The Docker documentation also describes installing Docker Engine from the official repository, which may be a better choice for a long-term environment. We run Warden without sudo, so our user needs access to Docker (usually through the docker group).
Installing Warden
We install Warden with Homebrew or clone it from the repository.
Homebrew:
brew install davidalger/warden/warden
warden svc up
Git:
sudo mkdir /opt/warden
sudo chown $(whoami) /opt/warden
git clone -b master https://github.com/davidalger/warden.git /opt/warden
echo 'export PATH="/opt/warden/bin:$PATH"' >> ~/.bashrc
PATH="/opt/warden/bin:$PATH"
warden svc up
Creating a WordPress project with Warden and Docker
We create a folder named example and enter it.
mkdir example
cd example/
In the folder we start the Warden services and create the .env file with these commands:
warden svc up
warden env-init
After env-init we enter the project name example, then the project type wordpress. If Warden does not ask for these values, we pass them as arguments: warden env-init example wordpress.
We build and start the environment containers:
warden env up -d --build
For the site to work over HTTPS, we add a certificate:
warden sign-certificate example.test
Now we open a shell in the container of our example.test project:
warden shell
In the container shell, in the project root, we download the latest WordPress version, extract it and remove the archive:
wget https://wordpress.org/latest.tar.gz
tar xfz latest.tar.gz
mv wordpress/* ./
rmdir ./wordpress/
rm -f latest.tar.gz
Adding the domain to /etc/hosts
For the browser to reach our site, we add the domain to the hosts file. We open it with administrator rights (in a new terminal window, outside the container):
sudo nano /etc/hosts
In the file we add a new line:
127.0.0.1 example.test
Now we can open the site: https://example.test. If the browser reports a certificate error, check the Warden documentation for how to add the Warden CA certificate to the trusted ones.
The WordPress setup screen appears.

Installing WordPress
For the installation we need the database connection details and the host. They are in the .env file in the example project folder. We go to the project folder (outside the container) and print the file:
cat .env
The file contains these values:
WARDEN_ENV_NAME=example
WARDEN_ENV_TYPE=wordpress
WARDEN_WEB_ROOT=/
TRAEFIK_DOMAIN=example.test
TRAEFIK_SUBDOMAIN=app
MARIADB_VERSION=10.4
NODE_VERSION=10
PHP_VERSION=7.4
WARDEN_DB=1
WARDEN_REDIS=0
APP_ENV=local
APP_DEBUG=true
DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=wordpress
DB_USERNAME=wordpress
DB_PASSWORD=wordpress
The MariaDB, Node.js and PHP versions depend on the Warden version, so your file may show different ones.
The database name, user and password are in DB_DATABASE, DB_USERNAME and DB_PASSWORD.
We still need the database host name. We read it with this command in the terminal:
docker ps
We get a list of the running containers. The host name is tied to the mariadb engine:
78582457150a wardenenv/mariadb:10.4 "docker-entrypoint.s…" 22 minutes ago Up 22 minutes 3306/tcp example_db_1
In our case it is example_db_1. Note: in Docker Compose v2 container names use hyphens instead of underscores (example-db-1), so always copy the name from your own docker ps output. Because WordPress runs in the same Docker network as the database, the service name from DB_HOST (db) usually works too.
In the WordPress setup we enter the details of our project.

We continue. We enter the site title and the name and password of the administrator user. Done: we have a WordPress project running in Docker with Warden.

Common problems
- The
wardencommand is not found. Open a new terminal window or check that the/opt/warden/bindirectory is in thePATHvariable. - A Docker permission error. The user needs access to Docker without
sudo. This usually means membership in thedockergroup and logging in again. - The browser does not open
example.test. Check the entry in/etc/hostsand whether the containers are running (docker ps).
Summary
With the Warden CLI we created a WordPress project in Docker. Preparing the environment is quick. Warden also lets us run several environments with different WordPress projects. Each runs locally under its own domain and does not collide with the others.
See also our other articles: Useful articles.