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.
version: "3"services: wordpress: depends_on: - db image: wordpress:latest volumes: - wp_data:/var/www/html ports: - "80:80" restart_policy: condition: on-failure environment: WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_USER: wordpress WORDPRESS_DB_PASSWORD: my_wordpress_db_password
db: image: mariadb volumes: - db_data:/var/lib/mysql restart_policy: condition: on-failure environment: MYSQL_ROOT_PASSWORD: my_db_root_password MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: my_wordpress_db_passwordvolumes: wp_data: db_data:
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:
sudo apt-get update
- Install required packages to allow apt to install repositories over HTTPS:
sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ software-properties-common
- Add Docker’s official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
- Add the stable branch repo to your mirrors list:
sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable"
- Update again now that Docker has been added:
sudo apt-get update
- Finally, install Docker-Ce:
sudo apt-get 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:
sudo curl -L "https://github.com/docker/compose/releases/download/1.23.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
- Ensure the binary has permission to be executed:
sudo chmod +x /usr/local/bin/docker-compose
- Verify by checking the version:
docker-compose --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:
docker-compose up -d
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.