DEV Community

Cover image for Containerized WordPress and MariaDB on AWS EC2
Muhammad Awais Zahid
Muhammad Awais Zahid

Posted on • Edited on

1

Containerized WordPress and MariaDB on AWS EC2

Summary of Tasks:

  1. Create a virtual machine on AWS

  2. Setup docker and docker-compose on VM

  3. Write a docker-compose file

  4. Execute docker-compose file

  5. Access your web server with VM public IP

  6. Set-up Database

  7. Watch my complete video of this project for troubleshooting

1. Create a virtual machine on AWS

Sign in to your AWS account and click on "Launch instance".
Choose Amazon Linux AMI or keep it default

Choose Amazon Linux AMI or keep it default

In the instance type section, choose t2.micro and a key-pair

In the instance type section, choose t2.micro and a key-pair

In the networking section, keep the default settings

In the networking section, keep the default settings

In the storage and advance section, use default settings and click on the "Launch Instance" button on the right top corner

In the storage and advance section, use default settings and click on the

Your virtual machine is ready

Your virtual machine is ready

2. Setup docker and docker-compose on VM



yum install docker -y
service docker start

Enter fullscreen mode Exit fullscreen mode


curl -SL https://github.com/docker/compose/releases/download/v2.20.3/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose

sudo chmod +x /usr/local/bin/docker-compose;

Enter fullscreen mode Exit fullscreen mode



  1. Write a docker-compose file




services:
wordpress:
container_name: wordpress_web
image: wordpress
ports:
- "80:80"
volumes:
- ./efs:/var/www/html
networks:
- web_cont_net
environment:
WORDPRESS_DB_HOST: mariadb
WORDPRESS_DB_USER: root
WORDPRESS_DB_PASSWORD: awais123
WORDPRESS_DB_NAME: cloud_db

mariadb:
container_name: wordpress_db
image: mariadb
environment:
MYSQL_ROOT_PASSWORD: awais123
MYSQL_DATABASE: cloud_db
volumes:
- ./database:/var/lib/mysql
networks:
- web_cont_net
networks:
web_cont_net:

Enter fullscreen mode Exit fullscreen mode



  1. Execute docker-compose file




docker-compose up -d

Enter fullscreen mode Exit fullscreen mode



  1. Access your web server with VM public IP

you will see such an interface

you will see such an interface

6. Set-up Database

Set-up Database

And your application is ready

And your application is ready

7. Watch my complete video of this project for troubleshooting

If you face any issues, watch my complete video of this project on my channel

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more