Docker Compose Project

Docker Compose Project

Β·

9 min read

🐳🌐 Migrating an eCommerce Web application from Server Based Platform to Docker Containers 🐳🌐

πŸ”—Follow me on:

LinkedIn | GitHub | YouTube | Medium |

🌐 www.praful.cloud

πŸ”—Project Repo: https://github.com/prafulpatel16/docker-projects.git

πŸ› οΈ Tools & Technologies covered:

πŸ—οΈPlatform Stack:

VS Code IDE

Docker Desktop

Docker client

Docker Hun(Registry)

Docker Compose

πŸ—οΈApplication stack:

Web Technology: PHP

Database: MySQL

Webserver: apache

Database Administration: phpMyAdmin

πŸš€ Diving into Docker: Transforming Software Deployment

Docker Features:

  1. Containerization Magic: Docker enables the encapsulation of applications and their dependencies into isolated containers, ensuring consistency and eliminating the "works on my machine" dilemma.

  2. Immutable Images: Docker images contain everything an application needs to run, making them portable, versioned, and consistent across different environments.

  3. Resource Efficiency: By sharing the host's kernel, Docker maximizes resource utilization while maintaining separation between applications.

  4. Rapid Deployment: Containers start almost instantaneously, facilitating agile scaling and efficient load balancing.

  5. Orchestration Possibilities: Docker plays well with orchestration tools like Kubernetes, simplifying the management of complex application deployments.

Docker Benefits:

  1. Consistency Across Environments: Docker ensures that applications behave the same way across development, testing, and production environments, eliminating unexpected surprises.

  2. Portability: Docker containers can run on any system that supports Docker, enabling easy migration across different environments.

  3. Scalability: Containers can be quickly scaled up or down, allowing applications to handle varying workloads seamlessly.

  4. Reduced Overhead: Docker containers share resources, enabling efficient utilization of server capacity and reducing overhead.

  5. Faster Time-to-Deployment: Docker accelerates the deployment process, streamlining the path from code to production.

βš™οΈ Mastering Multi-Container Applications with Docker Compose

Docker Compose Features:

  1. Declarative Composition: Docker Compose allows defining multi-container applications using a simple YAML file, detailing services, networks, and volumes.

  2. Service Definitions: Each component's image, environment variables, ports, and dependencies can be precisely defined within a Docker Compose file.

  3. Networking Magic: Docker Compose automatically creates networks for containers, facilitating seamless communication.

  4. Persistent Data Storage: Compose supports volume definitions, ensuring data persists beyond the lifespan of individual containers.

  5. Horizontal Scaling: Services can be scaled horizontally, replicating containers to handle increased workloads.

Docker Compose Benefits:

  1. Developer-Friendly Development: Compose simplifies local development environments by consolidating the application stack configuration into a single file.

  2. Effortless Deployment: With a single command, Compose spins up all defined containers, making deployment a breeze.

  3. Staging Simplicity: Compose ensures staging environments match production, reducing the chances of unexpected issues during deployment.

  4. Version Control Friendly: Compose files can be versioned, enabling teams to collaborate effectively on defining the application's architecture.

  5. Enhanced Testing: Docker Compose empowers developers to create isolated testing environments that mirror production configurations.

πŸ”— Conclusion: A New Paradigm for Software Deployment

Docker and Docker Compose have ushered in a new era of software development and deployment. Their powerful features and benefits have made containerization a cornerstone of modern software engineering. From ensuring consistency across environments to simplifying deployment pipelines, Docker and Docker Compose have proven indispensable for teams seeking efficiency, scalability, and agility.

πŸ“¦βœ¨ Title: Journey of Transformation: Migrating an eCommerce Platform to Containers

πŸ’πŸš€ Introduction: In the realm of tech innovation, migrating a server-based eCommerce application to containerized architecture can unlock unparalleled agility and scalability. In this blog post, we'll take a deep dive into the transformation journey of an imaginary company, "EcomTech," as they transition their eCommerce platform from a traditional server-based setup to a containerized architecture. We'll detail the steps, requirements, and tools used, including MySQL, phpMyAdmin, and the magic of Docker Compose.

πŸ› οΈ Requirements: Navigating the Transition:

The journey of migrating EcomTech's eCommerce application from server-based to containerized architecture involves several key requirements:

  1. Application Decomposition: Break down the monolithic server-based application into modular components suitable for containerization.

  2. Database Migration: Migrate the existing MySQL database to a containerized environment to ensure data consistency and scalability.

  3. Database Management: Integrate phpMyAdmin as a container to streamline database management, ensuring ease of use and access.

  4. Orchestration with Docker Compose: Leverage Docker Compose to orchestrate the various containers, ensuring smooth communication and coordination between services.

πŸš€ Step 1: Preparing for the Journey - Application Decomposition:

Dividing the monolithic application into smaller, container-ready components is crucial. EcomTech identified the core components such as product catalog, user authentication, and order processing. This decomposition facilitates better scaling and flexibility in the containerized environment.

πŸ”§ Step 2: Seamlessly Migrating the Database:

EcomTech decided to migrate their MySQL database to a containerized environment to ensure data consistency and portability. The process involved exporting the existing data and importing it into the MySQL container while ensuring data integrity.

πŸ’Ό Step 3: Empowering Database Management with phpMyAdmin:

To simplify database management, EcomTech integrated phpMyAdmin as a container. This provided them with an intuitive web interface to interact with the MySQL database and perform operations like query execution, table management, and more.

πŸ“¦ Step 4: Docker Compose Orchestration:

EcomTech's journey wouldn't be complete without Docker Compose. They crafted a meticulous docker-compose.yml file that defined services for the PHP application, MySQL database, and phpMyAdmin. Networking configurations were set to ensure seamless communication between containers while maintaining isolation.

πŸŽ‰ Conclusion: Embracing Innovation, Empowering eCommerce:

The transformation of EcomTech's eCommerce platform from a server-based architecture to containerized architecture marks a significant step towards innovation. The migration journey involved decomposing the application, migrating the MySQL database, and orchestrating the containers with Docker Compose. The result? A platform that's agile, scalable, and ready to navigate the dynamic eCommerce landscape.

Tags: #DockerCompose #Containerization #eCommerce #MySQL #phpMyAdmin

πŸ“¦βœ¨ Title: Navigating Transformation: Migrating eCommerce to Containers with Docker Compose

πŸ’πŸš€ Introduction: In the ever-evolving landscape of eCommerce, agility and scalability are paramount. Transitioning from conventional server-based architectures to containers, orchestrated by Docker Compose, brings a new dimension to deployment efficiency. This blog post will be your comprehensive guide to migrating a two-tier eCommerce web application from traditional server-based infrastructure to containerized architecture. We'll delve into deploying a PHP-based web application, integrating phpMyAdmin for database management, and harnessing the power of MySQL for data storage.

🧩 Understanding the Transition: Migrating from Server-Based to Containers:

Migrating to containers entails encapsulating application components, their dependencies, and configurations in isolated units, fostering flexibility and scalability. Docker Compose, an orchestration tool, streamlines the management of multi-container applications through declarative YAML files.

πŸ› οΈArchitecture:

🌐 Migrating the eCommerce Platform: From Conventional to Containerized:

πŸ“ Phase 1: Transition to Containerization

  • πŸ—οΈ Building the PHP Web Application Container: Containerize the PHP-based eCommerce application, enhancing its portability and maintainability.

Create a Local Development Environment

  1. Set up the docker project in VS Code

  1. Create a project folder "obbs" and import the web code application files

3. Create a Dockerfile from application source code

  1. Building a Docker image file. Go to the docker client terminal

$docker build .

Dockerfile build complete

docker image tag

docker image push to docker hub registry

πŸ—‚οΈ Phase 2: Elevating Database Management

  • πŸ›’οΈ Embracing MySQL for Data Storage: Migrate the MySQL database to a containerized environment for streamlined data management.

πŸ–₯️ Phase 3: Enriching Database Management Experience

  • 🧩 Empowering Database Management with phpMyAdmin: Elevate database management by integrating phpMyAdmin as an independent container.

🚒 Embarking on the Migration Journey:

βš™οΈ Step 1: Blueprinting with Docker Compose

  • πŸ“„ Creating the docker-compose.yml File: Define services for the PHP application, phpMyAdmin, and MySQL, specifying container images, ports, and environment variables.

version: "3.9"

services:
  # Database
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DBNAME: obbs
      MYSQL_PASSWORD: root
    container_name: mysql
    networks:
      - obbsweb
# phpmyadmin

  phpmyadmin:
    depends_on:
      - db
    image: phpmyadmin/phpmyadmin:4.7
    restart: always
    ports: 
     - '8081:80'
    environment:
      - PMA_HOST=mysql
      - PMA_PORT= 3306
      - PMA_ARBITRARY=1

    links:
     - db
    networks:
      - obbsweb
    volumes:
      - /sessions
    container_name: obbs-phpmyadmin

  # Webserver

  webserver:
    depends_on:
      - db
    image: praful2018/obbsweb:v1
    volumes:
      - phpweb_data:/var/www/html
    ports:
      - "8082:80"
    restart: always
    environment:
      MYSQL_HOST: mysql
      MYSQL_USER: root
      MYSQL_PASSWORD: root
      MYSQL_DBNAME: obbs
    networks:
      - obbsweb  
networks:
    obbsweb:   
volumes:
  db_data: {}
  phpweb_data: {}

βš™οΈ Step 2: Containerizing the PHP Application

  • 🧰 Configuring the PHP Application Container: Set up the PHP application container with its necessary dependencies and environment variables. Establish a smooth connection with the MySQL container.
# Webserver

  webserver:
    depends_on:
      - db
    image: praful2018/obbsweb:v1
    volumes:
      - phpweb_data:/var/www/html
    ports:
      - "8082:80"
    restart: always
    environment:
      MYSQL_HOST: mysql
      MYSQL_USER: root
      MYSQL_PASSWORD: root
      MYSQL_DBNAME: obbs
    networks:
      - obbsweb  
networks:
    obbsweb:   
volumes:
  db_data: {}
  phpweb_data: {}

βš™οΈ Step 3: Seamlessly Integrating phpMyAdmin

  • πŸ“Š Streamlining Database Management with phpMyAdmin: Configure the phpMyAdmin container to seamlessly interact with the MySQL container.
# phpmyadmin

  phpmyadmin:
    depends_on:
      - db
    image: phpmyadmin/phpmyadmin:4.7
    restart: always
    ports: 
     - '8081:80'
    environment:
      - PMA_HOST=mysql
      - PMA_PORT= 3306
      - PMA_ARBITRARY=1

    links:
     - db
    networks:
      - obbsweb
    volumes:
      - /sessions
    container_name: obbs-phpmyadmin

βš™οΈ Step 4: Transitioning and Configuring MySQL

  • πŸ—„οΈ Defining the MySQL Service: Establish the MySQL service within the docker-compose.yml file, configuring essential environment variables.
version: "3.9"

services:
  # Database
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DBNAME: obbs
      MYSQL_PASSWORD: root
    container_name: mysql
    networks:
      - obbsweb

βš™οΈ Step 5: Establishing Network Isolation and Data Persistence

  • πŸ“‘ Crafting a Secure Network: Create a dedicated network for containers' communication, prioritizing security and isolation.
networks:
    obbsweb:

βš™οΈ Step 6: Ensuring Data Persistence

  • πŸ“¦ Leveraging Docker Volumes: Employ Docker volumes to ensure the persistence of data for the MySQL database and other mission-critical application data.
volumes:
  db_data: {}
  phpweb_data: {}

βš™οΈ Step 7: Unveiling the Transformation

  • πŸš€ Running the Container Stack: Execute the entire application stack with the command docker-compose up, opening the doors to the eCommerce platform through a designated port.

$ docker compose up -d

Observed that three containers have running successfully

Go to Docker desktop and verify that the "obbs" application containers are running

Access "obbs-phpmyadmin"

phpMyAdmin app opened in browser

Login: root

Password: MySQL db password

Import obbs.sql database backup file to MySQL

Database imported successfully

Access Web application

Test the web application is launched and accessed successfully.

Web Home Page

Image description

Register

Login

Login successful

Services

Book a Service

Booking History

πŸ† Congratulations: Web Application successfully migrated to the docker containers

πŸ† Benefits of Migrating with Docker Compose:

  1. 🎯 Simplified Deployment: Docker Compose abstracts complexities, smoothing the deployment process.

  2. πŸ›‘οΈ Enhanced Isolation: Containers isolate components, mitigating potential conflicts.

  3. πŸ”„ Consistency Across Environments: Ensure uniform deployment across various environments.

  4. πŸ“ˆ Scalability: Seamlessly scale services as eCommerce demands evolve.

  5. βš™οΈ Resource Optimization: Docker Compose optimizes resource allocation.

πŸŽ‰ Conclusion: Pioneering the Future of eCommerce Deployment:

The transition from server-based infrastructure to containerized architecture with Docker Compose empowers your eCommerce platform with enhanced efficiency, flexibility, and scalability. This blog post has unraveled the migration journey, from containerizing the PHP application to integrating MySQL and phpMyAdmin. Embrace containerization, embrace innovation. Propel your eCommerce platform into a new era of deployment.

Tags: #DockerCompose #eCommerce #Containerization #DevOps #WebDevelopment #Cloud #CloudEngineer #aws #gcp #azure #oci #Docker #Dvops #Cloudjobs

πŸ“ About the Author: Praful Patel, an expert in Cloud/DevOps, is passionate about sharing insights and empowering the tech community. Explore more of my enlightening articles and follow me on

πŸ”—Follow me on:

LinkedIn | GitHub | YouTube | Medium |

🌐 www.praful.cloud

Β