
Australian entrepreneur and founder of Rubix Studios. Vincent specialises in branding, multimedia, and web development with a focus on digital innovation and emerging technologies.
Running WordPress in Docker offers a stable and repeatable local development setup. It eliminates environment-specific issues and simplifies service management. Using Docker alongside Visual Studio Code improves usability, especially for local development and customization.
Requirements
Ensure the following components are installed:
- Docker Desktop (Windows/macOS) or Docker Engine (Linux)
- Visual Studio Code with the Docker extension
Setup
Begin by creating a dedicated project folder.
- Open Visual Studio Code.
- Open a terminal in VS Code.
- Create a new directory for your project and navigate into it:
1mkdir wordpress2cd wordpress
Docker
Inside the project directory, create a docker-compose.yml file to define the services for WordPress and its dependencies.
- In Visual Studio Code, create a new file named docker-compose.yml.
- Add the following content to the file:
1services:2 db:3 image: mysql:9.34 volumes:5 - ./data/mysql:/var/lib/mysql6 restart: always7 environment:8 MYSQL_ROOT_PASSWORD: password9 MYSQL_DATABASE: wordpress10 MYSQL_USER: wordpress11 MYSQL_PASSWORD: wordpress12 networks:13 - wpsite1415 phpmyadmin:16 depends_on:17 - db18 image: phpmyadmin:latest19 restart: always20 ports:21 - '8080:80'22 environment:23 PMA_HOST: db24 MYSQL_ROOT_PASSWORD: password25 networks:26 - wpsite2728 wordpress:29 depends_on:30 - db31 image: wordpress:latest32 ports:33 - '8000:80'34 restart: always35 volumes:36 - wordpress_data:/var/www/html37 - ./wp-content:/var/www/html/wp-content:cached38 environment:39 WORDPRESS_DB_HOST: db:330640 WORDPRESS_DB_USER: wordpress41 WORDPRESS_DB_PASSWORD: wordpress42 networks:43 - wpsite4445volumes:46 wordpress_data:4748networks:49 wpsite:
Services
- db: MySQL 9.3 container with persistent storage
- phpmyadmin: Web interface for database management at http://localhost:8080
- wordpress: WordPress container accessible at http://localhost:8000, with local wp-content mapping
Startup
To launch your WordPress environment:
1docker-compose up -d
This starts the containers in detached mode. The initial setup can take a few minutes as Docker downloads the necessary images.
Visit http://localhost:8000 in your browser to complete the WordPress installation (language, site name, user credentials).
Container
On the first run, complete the WordPress installation in your browser by choosing a language and entering site credentials.
Management
Use the following commands for container control:
Stop
1docker-compose down
This stops and removes containers but retains volume data.
Restart
1docker-compose up -d
Customisation
To develop or install custom themes and plugins:
- Navigate to the wp-content/themes or wp-content/plugins directory in your project folder.
- Add or modify files directly.
- Changes reflect immediately in your running site.
Editing
Use Visual Studio Code to modify your WordPress setup:
- Open the project directory in VS Code.
- Edit themes, plugins, or core files.
- Save changes to see them reflected in the browser.
Docker simplifies local WordPress development by providing a containerized, consistent environment. When paired with Visual Studio Code, it allows efficient file management, rapid customization, and reliable performance across different systems.
Be the first to leave a comment.