Table of contents
In this article i will be guiding you how to host WordPress and MySQL using docker-compose command.
Requirements -
- Make sure docker is running with latest version. Click here for installation guide.
- Install latest version of docker-compose. Click here for installation guide.
Create directory and docker-compose file for Wordpress and DB.
First of all create a directory with any name. Here i will be using "project" name.
mkdir wordpress-docker
Go inside the folder and create docker-compose.yml and open it with you favorite text editor-
vim docker-compose.yml
paste the following lines and customize it as per your requirement.
version: '3'
services:
db:
image: mysql:latest
container_name: mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: securePassword #please use some complex password
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: password #please use some complex password
volumes:
- "./db:/var/lib/mysql"
wordpress:
depends_on:
- db
image: wordpress:latest
container_name: wordpress
restart: always
ports:
- "8000:80" #change ports as per your requirment
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: password #please use some complex password
WORDPRESS_DB_NAME: wordpress
volumes:
- "./wordpress:/var/www/html"
Save it and run following command to start the containers.
docker-compose up -d
Once containers are up open wordpress in browser- localhost:8000
Complete the installation process on browser.
Select your language-
Fill your username password and email -
Done, you have install wordpress on docker successfully.
If you have any doubts please drop a comment.