How to Setup WordPress Docker Containers on AWS. This article will look at WordPress and Docker benefits and then the workflow of setting it up on AWS through Docker.
What is WordPress
With such a wide user base, it is no surprise that many cloud providers and cloud services have dedicated resources to ensure robust integration with WordPress. Since WordPress websites need server space to be hosted, most cloud services like Azure and AWS offer this service in simple way. Alternatively, users can set up WordPress on a cloud service using Docker container technology.
This article about how to Setup WordPress Docker Containers on AWS. This is the WordPress instance on the cloud and how the whole process looks.
- Open source and easy to Use with multiple plugins (22,000+ plugins)
- Enable WordPress SSO with any identity provider like Office 365.
- Stable and innovative.
- WordPress is browser based so manage your site from anywhere.
- Very SEO friendly (H1, H2, H3 tags).
- It is an easy WordPress content management.
- Sharing ability (widgets for the social media, plug-ins, APIs).
- 100% Customizable design of your website
- Multiple users.
- Stable and innovative.
What is Docker
Docker s a containerization tool that allows you to set up separate “containers” where you setup development environment. The containers are similar to virtual machines, but without the need to install a complete operating system to be able to run them. These are developed and maintained in a virtualized container space, with its libraries and other dependencies that are self contained and separate from the server.
Docker Container technology, especially Docker, is getting increasingly common throughout the industry. Developers have made containers an essential component of their development workflow due to their flexibility, security and ease of use. Additionally, developers can use Docker Hub to get an official container image for some technology and after constructing the container you can start developing within it immediately.
WordPress Docker Pros
- Both services can provide excellent accessibility and ease of use to the user, independently and together.
- WordPress and Dockers give their users the freedom to configure the services themselves and provide them with premade options as well.
- In WordPress users can design both components as per preference or utilize the wide variety available at dedicated marketplaces for both.
- For Docker, users can make their own container and container image from scratch or take one from Docker Hub.
- No Need to Set Up (Multiple) Server Environments.
- Less Resource Heavy Than a Virtual Machine.
- Can Be Used on Any Platform.
- Share your containers to ease collaborations.
How to Setup WordPress Docker Containers on AWS
Setup WordPress with Docker on AWS
Seeing container technology’s rise in popularity, all major cloud services, like AWS, now offer dedicated container services. These services help configure Docker AWS functionality and simplify all the other container tasks. Regardless of the cloud platform, developers can instantly go from developing their application in a native environment to doing so in the cloud thanks to the container services.
Today, we are looking at the specific case of bringing WordPress to AWS by utilizing the power of Docker containers. After setting up and configuring the WordPress container, we will deploy the container to an instance of the AWS EC2 service. That way we will have a WordPress site up and running on the AWS platform and this process will be a good example of how containers can reduce many issues.
WordPress Docker Compose
We will firstly configure our WordPress container inside a file called a Docker Compose file. Such files are for specifying the services that the container will be running. While you can configure your own per your preference, this example will take a premade file from Docker’s own ‘awesome-compose’ repository.
Please go to the directory where the Compose file is saved and I run the following command.
$ docker-compose up -d
$ docker-compose ps
After confirming that everything is working well locally, it’s time to shoot for the cloud.
Deploy WordPress Docker Container on AWS
Since we are now moving to the cloud, we should look at the Docker Compose file that we worked on locally. It will require some changes to work in the cloud as per the new environment.
version: '3.7' services: db: image: mysql:8.0.19 command: '--default-authentication-plugin=mysql_native_password' restart: always volumes: - db_data:/var/lib/mysql environment: - MYSQL_ROOT_PASSWORD=wordpressrootpassword - MYSQL_DATABASE=test_wordpress - MYSQL_USER=emad - MYSQL_PASSWORD=wordpresspassword wordpress: image: wordpress:latest ports: - 80:80 restart: always environment: - WORDPRESS_DB_HOST=db - WORDPRESS_DB_USER=emad - WORDPRESS_DB_PASSWORD=wordpresspassword - WORDPRESS_DB_NAME=test_wordpress volumes: db_data:
We have to choose a database service for the particular EC2 instance because ECS in Docker does not support volumes within Compose support. We go to the AWS console to get an Amazon Relational Database Service (RDS) for us.
Next we configure the RDS instance to have the password specified in our Docker Compose file above. We also open the summary of our RDS instance to get its database hostname and put it in our Compose file.
With our RDS instance running, it is time to modify the Compose file. The file will get much smaller because we will remove the db service present and specify that we are using a separate database instance. The file now looks like this:
version: '3.7' services: wordpress: image: wordpress:latest ports: - 80:80 restart: always environment: WORDPRESS_DB_HOST: wordpressdbecs.c1unvilqlnyq.eu-west-3.rds.amazonaws.com:3306 WORDPRESS_DB_USER: wordpress WORDPRESS_DB_PASSWORD: wordpress123 WORDPRESS_DB_NAME: wordpressdbecs
Now, after our container is ready to be deployed on the cloud environment and go from simply WordPress to an AWS WordPress instance, we head to our final stage. We will use the Docker CLI because it supports direct interaction with ECS.
docker ecs setup
We will set the following characteristics for the example:
- Name of the instance: test_ecs
- Name of the AWS profile: ecstestprofile
- Region: (same as the deployed RDS database).
Afterwards you’ll need to enter AWS access key or, if using CLI, you can use N to put in user credentials.
With all the above steps done, we can use the following command to check if the ECS context is successfully created or not.
docker context ls
Once successful, we switch to our ECS context to deploy our container with the following command.
docker context use test_ecs
With the following command, we deploy our Docker Compose file through this command. This command then checks the log to see if WordPress is working correctly.
docker test_ecs compose up docker test_ecs compose logs
The security group of the RDS instance doesn’t have our WordPress container project; therefore, WordPress will not be able to connect to the database. We access the settings and within choose security groups, choose your instance.
Running the following command would get us the link to our WordPress site if the deployment was successful. The image below it should be what shows up in case of successful deployment.
docker ecs compose ps
And so, we have WordPress deployed in the cloud and an instance that can run locally. Thanks for reading about how to Setup WordPress Docker Containers on AWS.
How to Setup WordPress Docker Containers on AWS Conclusion
Running WordPress in the cloud is significantly easier than running and maintaining it locally. By connecting it with a cloud database instance like above, a user no longer having to worry about limitations that come with physical resources. If the user chooses to scale up and expand their WordPress website to involve more plugins, that is significantly easier. Traditionally, bringing WordPress to the cloud would have been difficult, but with Docker, the process is massively simplified.