In this blog post, I’ll show you how to setup WordPress and MySQL environment on Docker using Docker Compose In less than two minutes.
This article follows my last article where I showed how to setup 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 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.
2 replies on “Use Docker Compose to Setup WordPress And MySQL”
[…] came across the need to do that when I was playing and testing all kind of configuration with Docker Compose and found that if nothing was running inside the container it stopped after a few […]
[…] most basic command to start a Docker Compose project is below with the -d switch which detaches you from the container otherwise you will be […]