Use WordPress locally with Docker using Docker compose
Dockerfilefor extending a base image and install wp-cli- Using a custom Docker image with automated build on Docker Hub
- Local domain ex
myapp.local - Custom nginx config in
./nginx - Custom PHP
php.iniconfig in./config - Volumes for
nginx,wordpressandmariadb - WordPress using Bedrock - modern development tools, easier configuration, and an improved folder structure
- CLI scripts
- Create a self signed SSL certificate for using https
- Trust certs in macOS System Keychain
- Setup the local domain in your in
/etc/hosts
Install Docker
cd cli && ./create-cert.shEdit the script to your your custom domain, this example uses myapp.local
Chrome and Safari will trust the certs using this script.
In Firefox: Select Advanced, Select the Encryption tab, Click View Certificates. Navigate to where you stored the certificate and click Open, Click Import.
cd cli && ./trust-cert.shEdit the script to your your custom domain, this example uses myapp.local
cd cli && ./setup-hosts-file.shFollow the instructions. For example use
myapp.local
cd src
cp .env.example .envUse the following database settings:
DB_HOST=mysql:3306
DB_NAME=myapp
DB_USER=root
DB_PASSWORD=passwordcd src
composer installYou can also use composer like this:
docker-compose run composer update
docker-compose up -d🚀 Open up https://myapp.local
When making changes to the Dockerfile, use:
docker-compose up -d --force-recreate --buildold. => new.
docker exec -it myapp-wordpress bash
wp search-replace https://olddomain.com https://myapp.local --allow-root
- Added Linux support. Thanks to @faysal-ishtiaq.
Login to the docker container
docker exec -it myapp-wordpress bashStop
docker-compose stopDown (stop and remove)
docker-compose downCleanup
docker-compose rm -vRecreate
docker-compose up -d --force-recreateRebuild docker container when Dockerfile has changed
docker-compose up -d --force-recreate --build