Create docker-compose file for WordPress and MySQL.

Create docker-compose file for WordPress and MySQL.

In this article i will be guiding you how to host WordPress and MySQL using docker-compose command.

Requirements -

  1. Make sure docker is running with latest version. Click here for installation guide.
  2. 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'
        image: mysql:latest
        container_name: mysql
        restart: always
            MYSQL_ROOT_PASSWORD: securePassword  #please use some complex password
            MYSQL_DATABASE: wordpress
            MYSQL_USER: wordpress
            MYSQL_PASSWORD: password #please use some complex password
            - "./db:/var/lib/mysql"
            - db
        image: wordpress:latest
        container_name: wordpress
        restart: always
            - "8000:80"  #change ports as per your requirment
            WORDPRESS_DB_HOST: db:3306
            WORDPRESS_DB_USER: wordpress
            WORDPRESS_DB_PASSWORD: password #please use some complex password
            WORDPRESS_DB_NAME: wordpress
            - "./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-

Screenshot 2022-12-05 at 4.52.35 PM.png

Fill your username password and email -

Screenshot 2022-12-05 at 4.53.23 PM.png

Done, you have install wordpress on docker successfully.

If you have any doubts please drop a comment.

Did you find this article valuable?

Support Abhishek Singh by becoming a sponsor. Any amount is appreciated!