How to Deploy the Mall Project with Docker and Docker Compose: A Complete Guide
Deploy the macrozheng/mall e-commerce platform by orchestrating infrastructure and application containers with docker-compose -f docker-compose-env.yml -f docker-compose-app.yml up -d, which provisions MySQL, Redis, Elasticsearch, and three Spring Boot microservices in an integrated stack.
The macrozheng/mall repository provides a production-ready e-commerce solution packaged for containerized deployment. This guide explains how to deploy the mall project with Docker and Docker Compose using the official configuration files found in document/docker/ and document/sh/.
Architecture Overview
The deployment follows a two-tier architecture that separates supporting infrastructure from business logic.
Infrastructure Layer (docker-compose-env.yml)
The document/docker/docker-compose-env.yml file defines all middleware required by the mall platform. This includes MySQL 5.7 for relational data, Redis 7 for caching, MongoDB 4 for document storage, RabbitMQ 3.9 for messaging, Elasticsearch 7.17.3 with Logstash and Kibana for search and logging, MinIO for object storage, and Nginx 1.22 as the reverse proxy.
Each service mounts persistent volumes under /mydata/ host directories to prevent data loss during container recreation.
Application Layer (docker-compose-app.yml)
The document/docker/docker-compose-app.yml file orchestrates the three core Spring Boot applications: mall-admin (back-office management), mall-search (product search service), and mall-portal (front-end API gateway). These services use custom images based on OpenJDK 8 and connect to infrastructure via external_links and depends_on directives, resolving hostnames like db, redis, es, and rabbit.
Building Service Images
Before launching the stack, compile the Java artifacts and build container images using the provided Dockerfile.
The Base Dockerfile
Located at document/sh/Dockerfile, the build definition copies the compiled Spring Boot JAR into an OpenJDK 8 base image and configures the container entry point.
Build a service image manually:
cd mall-admin/target
docker build -t mall/mall-admin:1.0-SNAPSHOT -f ../../document/sh/Dockerfile .
Repeat this process for mall-search and mall-portal to generate the required application images.
Deploying the Full Stack
Execute the deployment using Docker Compose's multi-file approach to layer infrastructure beneath the applications.
Start the Infrastructure
First, initialize the database and middleware layer:
docker-compose -f document/docker/docker-compose-env.yml up -d
This command creates a dedicated Docker network and starts MySQL, Redis, MongoDB, RabbitMQ, Elasticsearch, Logstash, Kibana, MinIO, and Nginx containers.
Start the Application Services
Once the infrastructure health checks pass, deploy the business services:
docker-compose -f document/docker/docker-compose-env.yml \
-f document/docker/docker-compose-app.yml up -d
The -f flags merge both configuration files, ensuring the mall-admin, mall-search, and mall-portal containers can resolve dependencies via the shared network.
Verify the Deployment
Check container status and view logs:
docker-compose ps
docker logs -f mall-admin
Managing and Debugging the Deployment
Container orchestration requires routine operational commands for scaling, debugging, and cleanup.
Scaling Services
Scale any stateless service horizontally without modifying configuration files:
docker-compose -f document/docker/docker-compose-app.yml up -d --scale mall-admin=2
Ensure your Nginx upstream configuration distributes traffic across the scaled instances.
Debugging a Single Service
For isolated testing, run a service container manually with explicit port mapping and host links:
docker run -p 8080:8080 --name mall-admin \
-v /etc/localtime:/etc/localtime \
-e TZ="Asia/Shanghai" \
--link mysql:db \
mall/mall-admin:1.0-SNAPSHOT
Alternatively, use the convenience scripts in document/sh/ (such as run.sh or mall-admin.sh) which automate stop, remove, rebuild, and run operations.
Stopping and Cleaning Up
To stop all services and remove associated volumes (destructive):
docker-compose -f document/docker/docker-compose-env.yml \
-f document/docker/docker-compose-app.yml down -v
Omit the -v flag to preserve persistent data in /mydata/ directories for subsequent deployments.
Summary
- The macrozheng/mall project uses a two-file Docker Compose strategy:
docker-compose-env.ymlfor infrastructure anddocker-compose-app.ymlfor Spring Boot services. - Persistent volumes mounted under
/mydata/ensure database and storage data survives container restarts. - The
document/sh/Dockerfileprovides a standardized OpenJDK 8 base image for packaging the mall-admin, mall-search, and mall-portal JARs. - Cross-service communication relies on Docker's internal DNS and
external_linksconfiguration to resolve hostnames likedb(MySQL) andredis. - A single command merges both compose files to deploy the entire production-grade e-commerce stack.
Frequently Asked Questions
What infrastructure services does the mall project require?
The mall platform requires MySQL 5.7 for transactional data, Redis 7 for session caching, MongoDB 4 for document storage, RabbitMQ 3.9 for asynchronous messaging, Elasticsearch 7.17.3 with Logstash and Kibana for search and observability, MinIO for object storage, and Nginx 1.22 for static asset delivery. The document/docker/docker-compose-env.yml file defines all these services with proper volume mounts and environment configurations.
How do I build the mall service images locally?
Navigate to the target directory containing the compiled Spring Boot JAR (e.g., mall-admin/target) and execute docker build -t mall/mall-admin:1.0-SNAPSHOT -f ../../document/sh/Dockerfile .. The document/sh/Dockerfile uses OpenJDK 8 as the base image and configures the container to run the JAR with appropriate JVM settings. Repeat this process for mall-search and mall-portal to generate the three required application images.
Can I scale individual mall services with Docker Compose?
Yes, Docker Compose supports horizontal scaling of stateless services. Use the --scale flag when running the application compose file, such as docker-compose -f document/docker/docker-compose-app.yml up -d --scale mall-admin=2 to run two instances of the admin service. Ensure your load balancer (Nginx) is configured to distribute traffic across these instances.
Where does the mall project store persistent data?
All infrastructure services mount Docker volumes or host directories under /mydata/ subdirectories (e.g., /mydata/mysql/data, /mydata/redis/data). This configuration, defined in document/docker/docker-compose-env.yml, ensures that database files, Redis persistence, Elasticsearch indices, and MinIO objects remain intact even when containers are destroyed and recreated.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →