Docker is an open-source containerization platform that helps developers to set up a local development environment. It enables you to package applications into containers. However, if you are using more than one container for your application, you have to create several Docker files. Managing and monitoring all those containers is a time-consuming process. This is the place where Docker Compose comes into the picture.
Docker Compose is a tool used to defines and runs a multi-container Docker application. This will solve your problem by allowing you to use a YAML file to manage multiple containers at once. You can set any number of containers, define volumes, images, builds then use a single command to run and manage all containers. Here is a nice guide on how to install Docker Compose AWS.
Most applications are built from several components. In this case, Docker Compose will allow you to define and run all these components from a single file. WordPress is a good example of a stack application. WordPress consists of a web server container, database container, and phpMyAdmin container. You can create a simple YAML file to bundle these WordPress components. Then use Docker Compose to build, run, and inter-connect all WordPress containers to host a WordPress CMS. You should also read install wordpress on aws ubuntu.
In this post, we will demonstrate how to install WordPress CMS using Docker Compose on Ubuntu 20.04 server.
Step 1: Installing Docker Engine
Before starting, Docker must be installed on your system. If you are installing Docker for the first time, you will need to set up the Docker repository in your system.
First, install required dependencies using the following command:
You also need to install Docker Compose in your system. The latest version of Docker Compose is not included in the Ubuntu default repository. So you will need to download it from the Git Hub download page.
Run the following command to download the current stable release of Docker Compose:
Next, set the executable permission to the downloaded binary:
chmod +x /usr/local/bin/docker-compose
Next, verify the Docker Compose version using the command below:
docker-compose --version
Sample output:
docker-compose version 1.29.2, build 5becea4c
Step 3: Setting Up YML File
Next, you will need to create a docker-compose.yml file to define, WordPress container, Database container, Volume, and Environment. This will tell Docker how to configure and start the WordPress and Database container.
First, create a WordPress directory to hold your docker-compose.yml file:
mkdir wordpress
Next, create a docker-compose.yml file using the following command:
nano wordpress/docker-compose.yml
Add the following code to define Docker Compose version, wordpress and database service, volumes and environment:
You can check both container images downloaded by the dokcer-compose.yml file using the command below:
docker-compose images
Sample output:
Container Repository Tag Image Id Size
---------------------------------------------------------------------
wordpress_database_1 mysql latest c60d96bd2b77 513.8 MB
wordpress_wordpress_1 wordpress latest baf5889057ff 550.7 MB
Next, verify the running container with the following command:
docker-compose ps
Sample output:
Name Command State Ports
-------------------------------------------------------------------------------------------------
wordpress_database_1 docker-entrypoint.sh mysqld Up 3306/tcp, 33060/tcp
wordpress_wordpress_1 docker-entrypoint.sh apach ... Up 0.0.0.0:80->80/tcp,:::80->80/tcp
At this point, your WordPress site is ready. Now, open your web browser and type the URL http://your-server-ip. You will be redirected to the WordPress language selection screen:
Select your preferred language and click on the Continue button. You should see the WordPress site configuration screen:
Provide your website name, admin username, password, email, and click on Install WordPress. Once the installation is completed, you should see the following screen:
Click on Log in button. You will be redirected to the WordPress login screen:
Provide your WordPress admin username, password and click on Login button. You will be redirected to the WordPress dashboard as shown below:
Step 6: Updating WordPress Container
If your WordPress and MySQL Docker images have changed since the container was created, you can update them by stopping and recreating all containers again.
First, stop all containers using the following command:
cd wordpress
docker-compose down
Next, download the latest version of WordPress and MySQL image using the following command:
docker-compose pull
Next, create and launch both container using the following command:
docker-compose up -d
Conclusion
Your WordPress website is now up and running in a containerization environment. I hope you have now enough understanding of how Docker Compose works and helps you to set up a WordPress website within a minute.
I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.
32votes
Article Rating
Subscribe
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.
DisagreeAgree
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.