This project demonstrates how to containerize a complete Medusa.js e-commerce stack with Docker:
- Medusa Backend: Core e-commerce engine
- Admin Panel: Dashboard for store management
- Next.js Storefront: Customer-facing frontend application
- PostgreSQL: Database for data persistence
- Redis: For caching and pub/sub functionality
The project uses a well-structured architecture that separates source code from Docker configurations, providing better control over development and production environments.
store-medusa-docker/
├── docker-compose.yml # Main Docker Compose configuration
├── docker-compose.override.yml # Development overrides
├── docker-compose.prod.yml # Production settings
├── admin/ # Admin panel Docker configuration
│ ├── Dockerfile
│ └── Dockerfile.prod
├── backend/ # Medusa backend Docker configuration
│ ├── Dockerfile
│ ├── Dockerfile.prod
│ └── develop.sh
├── storefront/ # Next.js storefront Docker configuration
│ ├── Dockerfile
│ └── Dockerfile.prod
├── my-medusa-store/ # Medusa backend source code
│ ├── package.json
│ ├── medusa-config.ts
│ └── ...
├── my-medusa-store-storefront/ # Next.js storefront source code
│ ├── package.json
│ ├── next.config.js
│ └── ...
└── README.md # Project documentation
This project uses a separation of concerns approach:
-
Source Code Directories:
my-medusa-store- Backend Medusa application generated withcreate-medusa-appmy-medusa-store-storefront- Storefront Next.js application
-
Docker Configuration Directories:
backend/- Contains Dockerfile for Medusa backendadmin/- Contains Dockerfile for admin panelstorefront/- Contains Dockerfile for Next.js storefront
This separation provides better control over the build process for different environments, making it easier to maintain and deploy.
- Docker and Docker Compose installed on your system
- Git
- Clone the repository:
git clone https://github.com/yourusername/store-medusa-docker.git
cd store-medusa-docker- Build and start the development environment:
docker compose up --buildAfter the initial build, you can start the containers without rebuilding:
docker compose up- Access your applications at:
- Medusa Server: http://localhost:9000
- Medusa Admin: http://localhost:7000
- Storefront: http://localhost:8000
- PostgreSQL: localhost:5432
- Redis: localhost:6379
Note: If you change the dependencies of your projects by adding new packages, rebuild the affected service with
docker compose up --buildto update your environment.
Add sample data to your store:
docker exec medusa-server medusa seed -f ./data/seed.jsonThis repository contains Dockerfiles for both development (Dockerfile) and production (Dockerfile.prod).
The production Dockerfiles create optimized images based on your local development progress:
- Build and run production containers:
docker compose -f docker-compose.yml -f docker-compose.prod.yml up --build -d- For subsequent runs without rebuilding:
docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d- Development Mode: Fast rebuilds with volume mounting for efficient development
- Production Mode: Optimized builds for deployment
- Data Persistence: Configured volumes for database data
- Environment Isolation: Separate configurations for development and production
- Hot Reloading: Changes to source code are reflected immediately in development
Create appropriate .env files in each project directory. Sample templates:
-
For backend (
my-medusa-store/.env):JWT_SECRET=your_jwt_secret COOKIE_SECRET=your_cookie_secret DATABASE_URL=postgres://postgres:postgres@postgres:5432/medusa-docker REDIS_URL=redis://redis:6379 -
For storefront (
my-medusa-store-storefront/.env):NEXT_PUBLIC_MEDUSA_BACKEND_URL=http://localhost:9000
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
docker-compose.production.yml contains production relevant overrides to the services described in the docker-compose.yml development file.
curl -X GET localhost:9000/store/products | python -m json.tool
After the seed script has run you will have the following things in you database:
- a User with the email: admin@medusa-test.com and password: supersecret
- a Region called Default Region with the countries GB, DE, DK, SE, FR, ES, IT
- a Shipping Option called Standard Shipping which costs 10 EUR
- a Product called Cool Test Product with 4 Product Variants that all cost 19.50 EUR
Visit docs.medusa-commerce.com for further guides.
Website | Notion Home | Twitter | Docs