diff --git a/README.md b/README.md index 8310d21..3a8e83e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,3 @@ - # Assignment: Dockerizing WordPress with Dockerfile, Docker Compose, and Database Optimization ### Objective: The goal of this assignment is to Dockerize a WordPress application using best practices for Dockerfile and Docker Compose, as well as to optimize the database for improved performance. You are also required to create a Readme file to document your approach and provide additional notes related to the task. @@ -13,7 +12,7 @@ Tasks: * Create a Docker Compose file (docker-compose.yml) to orchestrate the WordPress application. * Include services for WordPress and the database (e.g., MySQL or MariaDB). * Configure network settings and dependencies between services. -* Use environment variables or .env files to manage configuration settings securely. +* Use environment variables to manage configuration settings securely. ### 3) Optimize the Database for Performance: * Research and implement database optimization strategies to enhance performance. * Consider techniques such as indexing, caching, and query optimization. @@ -42,3 +41,82 @@ Your assignment will be evaluated based on the following criteria: Note: Please make sure to test your Dockerized WordPress application thoroughly to ensure it functions as expected. Good luck with your assignment! If you have any questions or need further assistance, feel free to ask. +Approach for Dockerizing WordPress : Gone through the official Docker documentation on WordPress & write the Dockerfile and docker-Compose.yml file with the help of the documentation and some of my prior knowledge on networking and docker. + +Approach for optimizing the database : Research about different database optimization strategies. Having the basic knowledge of MYSQL queries given a big advantage. + +Challenges encountered during the process : My laptop was having some issues related to storage. So, i had to used a AWS EC2 instance. +## Deployment + Step 1: +Build the Docker image using the following command: +```bash + docker build -t my-wordpress-image . +Once the image is built, you can verify its existence by running: + docker image +``` +To run the container from image +```bash + docker run -p 8080:80 --name my-wordpress-container my-wordpress-image +``` +To get access of the website just hit the following url in the browser +```bash + http://localhost:8080 +``` + +## Step 2: +To start containers defined in a 'docker-compose.yml' +```bash + docker-compose up -d +``` +To get access of the website just hit the following url in the browser +```bash + http://localhost:8081 or http://your-server-ip +``` +## Step 3: +To access the MySQL Container +```bash + docker exec -it my-mysql bash +``` +To log in to MySQL and enter the password +```bash + mysql -u root -p +``` +To use databse and showing the tables +```bash + use wordpress; + show table; +``` +To Analyze Query Performance : +Identify slow-running queries using the EXPLAIN statement +```bash + EXPLAIN SELECT * FROM wp_posts WHERE post_status = 'publish'; +``` +Indexing : +Identify frequently used columns adding indexes to them +```bash + CREATE INDEX idx_title ON wp_posts (post_title); +``` +Ensure that each table has a primary key +```bash + ALTER TABLE wp_posts ADD PRIMARY KEY (ID); +``` +Optimize Queries : Only retrieve the columns needed +```bash + SELECT post_title, post_date FROM wp_posts WHERE post_status = 'publish'; +``` +Regular Maintenance : Analyze and Optimize Tables +```bash +ANALYZE TABLE wp_posts; +OPTIMIZE TABLE wp_posts; +``` +Remove Unnecessary Data : Periodically remove old or unused data to reduce the size of your database. + +Partitioning (For Large Tables) : Partitioning them to distribute data across multiple partitions. + +Monitor Performance : Continuously monitor the performance of database using tools like MySQL's Performance Schema +## Documentation + +[Documentation]https://drive.google.com/file/d/1Hg1HVKEvQ1AfaMrXGnh9jTEAuk-m5YKL/view?usp=sharing + +[Project link] http://13.233.190.208/wp-admin/install.php + diff --git a/docker_compose.yaml b/docker_compose.yaml new file mode 100644 index 0000000..63c8c51 --- /dev/null +++ b/docker_compose.yaml @@ -0,0 +1,61 @@ +--- +version: '3.7' +services: + + --- +version: '3.7' +services: + + wordpress: + image: wordpress + restart: always + ports: + - 8080:80 + environment: + WORDPRESS_DB_HOST: db + WORDPRESS_DB_USER: manju + WORDPRESS_DB_PASSWORD_FILE: /run/secrets/db_password + WORDPRESS_DB_NAME: wpdb + secrets: + - db_password + volumes: + - wordpress:/var/www/html + + db: + image: mysql:5.7.28 + ports: + - "3306:3306" + environment: + MYSQL_DATABASE: wpdb + MYSQL_USER: manju + MYSQL_PASSWORD_FILE: /run/secrets/db_password + MYSQL_ROOT_PASSWORD_FILE: /run/secrets/db_root_password + secrets: + - db_password + - db_root_password + volumes: + - db:/var/lib/mysql + networks: + - default + + phpmyadmin: + image: phpmyadmin/phpmyadmin + links: + - db:db + ports: + - 8282:80 + environment: + MYSQL_USER: manju + MYSQL_PASSWORD_FILE: /run/secrets/db_password + MYSQL_ROOT_PASSWORD_FILE: /run/secrets/db_root_password + secrets: + - db_password + - db_root_password +secrets: + db_password: + file: db_password.txt + db_root_password: + file: db_root_password.txt +volumes: + wordpress: + db: