How to install and run WordPress locally with Docker

This is the easiest way to run a local instance of WordPress, so you can try out things for your blog before pushing it to a server. It’s extremely easy and you should be able to do it in a couple of minutes following 3 steps.

Step 1. Write you docker-compose

Create your docker compose file as follows.

version: "3.9"

services:

  wordpress:
    image: wordpress
    restart: always
    ports:
      - 8080:80
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: exampleuser
      WORDPRESS_DB_PASSWORD: examplepass
      WORDPRESS_DB_NAME: trip2019
    volumes:
     - wp_data:/var/www/html

  db:
    image: mysql:5.6
    restart: always
    environment:
      MYSQL_DATABASE: trip2019
      MYSQL_USER: exampleuser
      MYSQL_PASSWORD: examplepass
      MYSQL_ROOT_PASSWORD: example
    volumes:
      - db_data:/var/lib/mysql

  phpmyadmin:
    image: phpmyadmin
    restart: always
    ports:
      - 8081:80
    environment:
      - PMA_ARBITRARY=1
      - PMA_HOST=db
      - PMA_USER=exampleuser
      - PMA_PASSWORD=examplepass

volumes:
  db_data: {} 
  wp_data: {} 

Step 2. Run it

From your terminal, you can simply run this line (note that dc-wordpress.yml should be the path to your file).

docker-compose -f dc-wordpress.yml up

Step 3. Open it

You can now go to your browser on 127.0.0.1:8080 to open WordPress and proceed with the installation.

And 127.0.0.1:8081 to open phpMyAdmin, so you can also play around with your database using a front end.

This is extremely easy and simple. Next time we can show to use a web server like Nginx and maybe install a certificate.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.