DEV Community

Cover image for How Install WordPress with Docker
George Omara
George Omara

Posted on

How Install WordPress with Docker

What you need in order to get this to work successfully.

  • Docker
  • Docker Compose

Step 1:

This first thing that you need to do is to create a project folder to work in, and inside the project folder you create Docker Compose file.

Open a Terminal or Command Prompt inside the project directory and run the command below.

touch docker-compose.yaml
Enter fullscreen mode Exit fullscreen mode

Step 2:

Open the docker-compose.yaml file using a text editor of your choice.

Step 3:

Write the code below inside the docker-compose.yaml file and save.

version: '3.8'

services:
  wordpress:
    image: wordpress
    restart: always
    ports:
      - '8080:80'
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
    volumes:
      - wordpress:/var/www/html
  db:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
      MYSQL_RANDOM_ROOT_PASSWORD: '1'
    volumes:
      - db:/var/lib/mysql

volumes:
  wordpress:
  db:
Enter fullscreen mode Exit fullscreen mode

Step 4:

Go back to the Terminal or Command Prompt shell that you opened earlier, and enter the command below.

docker-compose up
Enter fullscreen mode Exit fullscreen mode

Docker Compose shall execute the script and install the WordPress and MySQL images from docker hub.
It will then go ahead and Spin up two containers, one for each image.

Wait for about 1 minutes after docker-compose shows done for both containers before you can load WordPress on your browser.

Step 5:

Navigate to http://localhost:8080 on your browser, and this is the page you should expect to see.

Image

Links:

Visit this GitHub repository, it has everything you need.

Top comments (3)

Collapse
 
vishalraj82 profile image
Vishal Raj

Here is my extension on your article - dev.to/vishalraj82/using-https-in-...

Collapse
 
omarageorge profile image
George Omara

Wow that's amazing!
I love it.

Collapse
 
vishalraj82 profile image
Vishal Raj

Than you George.