π³π 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:
Containerization Magic: Docker enables the encapsulation of applications and their dependencies into isolated containers, ensuring consistency and eliminating the "works on my machine" dilemma.
Immutable Images: Docker images contain everything an application needs to run, making them portable, versioned, and consistent across different environments.
Resource Efficiency: By sharing the host's kernel, Docker maximizes resource utilization while maintaining separation between applications.
Rapid Deployment: Containers start almost instantaneously, facilitating agile scaling and efficient load balancing.
Orchestration Possibilities: Docker plays well with orchestration tools like Kubernetes, simplifying the management of complex application deployments.
Docker Benefits:
Consistency Across Environments: Docker ensures that applications behave the same way across development, testing, and production environments, eliminating unexpected surprises.
Portability: Docker containers can run on any system that supports Docker, enabling easy migration across different environments.
Scalability: Containers can be quickly scaled up or down, allowing applications to handle varying workloads seamlessly.
Reduced Overhead: Docker containers share resources, enabling efficient utilization of server capacity and reducing overhead.
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:
Declarative Composition: Docker Compose allows defining multi-container applications using a simple YAML file, detailing services, networks, and volumes.
Service Definitions: Each component's image, environment variables, ports, and dependencies can be precisely defined within a Docker Compose file.
Networking Magic: Docker Compose automatically creates networks for containers, facilitating seamless communication.
Persistent Data Storage: Compose supports volume definitions, ensuring data persists beyond the lifespan of individual containers.
Horizontal Scaling: Services can be scaled horizontally, replicating containers to handle increased workloads.
Docker Compose Benefits:
Developer-Friendly Development: Compose simplifies local development environments by consolidating the application stack configuration into a single file.
Effortless Deployment: With a single command, Compose spins up all defined containers, making deployment a breeze.
Staging Simplicity: Compose ensures staging environments match production, reducing the chances of unexpected issues during deployment.
Version Control Friendly: Compose files can be versioned, enabling teams to collaborate effectively on defining the application's architecture.
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:
Application Decomposition: Break down the monolithic server-based application into modular components suitable for containerization.
Database Migration: Migrate the existing MySQL database to a containerized environment to ensure data consistency and scalability.
Database Management: Integrate phpMyAdmin as a container to streamline database management, ensuring ease of use and access.
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
- Set up the docker project in VS Code
- Create a project folder "obbs" and import the web code application files
3. Create a Dockerfile from application source code
- 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
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:
π― Simplified Deployment: Docker Compose abstracts complexities, smoothing the deployment process.
π‘οΈ Enhanced Isolation: Containers isolate components, mitigating potential conflicts.
π Consistency Across Environments: Ensure uniform deployment across various environments.
π Scalability: Seamlessly scale services as eCommerce demands evolve.
βοΈ 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