This repository offers a minimal Docker-based setup for WordPress development, enabling you to spin up a local environment quickly without complex configuration.
git clone https://github.com/djuric/wordpress-docker-setup myproject
cd myprojectCreate a .env file in the project root and configure the following variables:
PROJECT_NAME=yourproject
WORDPRESS_PORT=80
PHPMYADMIN_PORT=8081
MYSQL_PORT=3306
WORDPRESS_DB_USER=exampleuser
WORDPRESS_DB_PASSWORD=examplepass
WORDPRESS_DB_NAME=exampledbIMPORTANT: Your PROJECT_NAME needs to be the same as the name of your project folder. Docker containers and volumes will be named based on this prefix.
-
PROJECT_NAME
A unique name for your project. Used as a prefix for Docker containers, volumes, and networks to avoid conflicts with other projects. -
WORDPRESS_PORT
The port on your host machine used to access the WordPress site.Default is
80, but you can change it to something like8080.Note: Changing this to something other than
80will break network connection between host machine and container. This means that tools like curl will not work (hence cron jobs will not work either). -
PHPMYADMIN_PORT
The port used to access phpMyAdmin (database management UI).
Example:http://localhost:8081 -
MYSQL_PORT
The port exposed on your host for connecting to the database.
Useful if you plan to connect with tools like DBeaver or MySQL Workbench. -
WORDPRESS_DB_USER
The username for accessing the database. -
WORDPRESS_DB_PASSWORD
The password for accessing the database. -
WORDPRESS_DB_NAME
The name of the database.
Note: If you're running multiple instances of this setup, make sure each one uses a unique set of ports (e.g. 8080/8081/3306 for one, 8090/8091/3307 for another).
Instead of using docker compose manually (which requires extra flags to load environment variables), use the included start.sh script:
./start.shThis will:
- Load environment variables from
.env - Apply a unique Docker Compose project name using
PROJECT_NAME
To run multiple instances of this Docker setup (e.g., for different WordPress projects), you'll need to assign unique port numbers for each one to avoid conflicts.
- Use port numbers above 1024 (to avoid reserved system ports).
- Ensure the ports are not already in use by another process or Docker container.
- Avoid commonly used ports like
5432(PostgreSQL),6379(Redis), etc., unless you're sure they're not active.
| Instance | WordPress | phpMyAdmin | MySQL |
|---|---|---|---|
| siteA | 8080 | 8081 | 3306 |
| siteB | 8090 | 8091 | 3307 |
| siteC | 8100 | 8101 | 3308 |
This setup includes WP-CLI preinstalled in the WordPress container. You can run WP-CLI commands directly from your terminal using the provided ./wp.sh script.
Then you can run commands like:
./wp user list
./wp plugin install akismet --activate
./wp post list✅ No need to type
docker compose exec— the script handles it for you.❗ Make sure the project is up and running via
./start.shbefore using WP-CLI commands.
You can import a .sql file into your running MySQL container using the included mysql-import.sh script.
Run the import command:
./mysql-import.sh path/to/your-database-dump.sqlThis will:
- Copy the SQL file into the running MySQL container
- Run the import inside the container using credentials from your
.envfile
💡 If you're importing a full website, make sure the database you are importing into already exists and is completely empty (i.e., contains no tables).
After importing a database, you may need to update old URLs (e.g., from a production domain to localhost).
Use WP-CLI's search-replace command:
./wp search-replace 'https://old-domain.com' 'http://localhost'You can export your project's current database using the included mysql-export.sh script.
Run the export command:
./mysql-export.shThis will:
- Export the contents of your database using the credentials from
.env - Save the dump as a
.sqlfile in the project root directory