Use Docker Compose To Setup WordPress And MySQL

In this blog post, I’ll show you how to set up WordPress and MySQL environment on Docker using Docker Compose In less than two minutes.

NOTE: This article was replaced with a newer version.

This article follows my last article, where I showed how to set up WordPress and MySQL on Docker, Docker-compose will take the same process but will make it more robust.

About Docker Compose

Docker Compose is a tool for defining and running multi-container Docker applications using a YAML file to configure the application’s services.

Once the file Is created, I can start all the services using a single command.

Requirements

Docker Compose Installed on Windows Server 2016 host or Docker for Windows

Linux Containers -Because WordPress and MySQL are running on Linux I’ll need to use Linux Containers on Windows 10 or use Linux Containers on 1709.

Get started

To get started, I’ll create a folder where I’ll create my docker-compose file

Once the folder Is created, I’ll create a docker-compose.yml file with the code below.

version: ‘3’

services:

db:

image: mysql:5.7

volumes:

– db_data:/var/lib/mysql

restart: always

environment:

MYSQL_ROOT_PASSWORD: password1234

MYSQL_DATABASE: wordpress

MYSQL_USER: wordpress

MYSQL_PASSWORD: wordpress

wordpress:

depends_on:

– db

image: wordpress:latest

ports:

– “8000:80”

restart: always

environment:

WORDPRESS_DB_HOST: db:3306

WORDPRESS_DB_USER: wordpress

WORDPRESS_DB_PASSWORD: wordpress

volumes:

db_data:

Below, You can see the .YML file

Run Docker Compose

Next, I’ll run my Docker Compose file using the file below

docker-compose up -d

And Below, You can see my WordPress site.

Conclusion

Using Docker to test WordPress features and updates Is the most simple, safe and secure way.


Posted

in

by