Docker makes it easy to manage and develop online web applications and Docker-Compose makes it simple to manage multiple Docker containers. With only 2 containers and an incredibly simple configuration file, we can launch our own WordPress installation in under 10 minutes.
What is Docker?
Docker is a platform that allows you to isolate applications and all of their dependencies to a “container” that can easily be stopped, started, updated or removed at any time. Docker containers as they are called are automatically created from simple config files.
If you aren’t familiar with Docker, you should check out our previous post and video just on Docker!
What is Docker-Compose?
– Is what I aim to teach in our latest video “Learn Docker-Compose with WordPress” while subsequently setting up a WordPress website. Docker-Compose is another tool that builds on what we have learned about Docker.
In the real world, most applications require more than one “service” to run. A web application isn’t just a web application; it’s a database, a front-end application, a back-end server with an API service, and anything else that’s required to be running to allow the full application to function. Ideally, each “micro-service” is developed in their own separate docker container.
Docker-Compose allows us to bundle these containers together and interact with each other as a single application.
Creating a Docker-Compose.yml file
A docker-compose file for WordPress only requires two containers, the WordPress container, and a separate container for a database.
Save the file as docker-compose.yml
. To learn more about creating your own Docker-Compose files, watch the video above.
Install Docker
You can follow these directions directly from Docker’s own documentation: https://docs.docker.com/install/linux/docker-ce/ubuntu/#install-docker-ce
- Update the system with:
- Install required packages to allow apt to install repositories over HTTPS:
- Add Docker’s official GPG key:
- Add the stable branch repo to your mirrors list:
- Update again now that Docker has been added:
- Finally, install Docker-Ce:
Install Docker-Compose
Once Docker has been installed, install Docker-Compose. You can also follow this guide on the official docs: https://docs.docker.com/compose/install/#install-compose
- Download the latest version of Docker-compose:
- Ensure the binary has permission to be executed:
- Verify by checking the version:
Start Docker-Compose server
Once your server has Docker and Docker-Compose installed, we can launch our WordPress server.
- Move the
docker-compose.yml
file onto your sever in a location that makes sense for you (ex:~/wordpress/docker-compose.yml
). - From the
~/wordpress
directory run:
The -d
switch will cause docker-compose to run in the background as a daemon, which will allow you to close the shell without ending the docker-compose session.
You’re finished!
You can now visit your WordPress blog by visiting the IP address of your server. You will be greeted with the setup page.