Skip to content

This repo is managed by the Medusa Community. Medusa does not provide official support for Docker, but we will accept fixes and documentation. Use at your own risk.

Notifications You must be signed in to change notification settings

acelest/docker-medusa

 
 

Repository files navigation

Medusa

🚀 Dockerized Medusa.js E-Commerce Project

A complete dockerized e-commerce solution with Backend, Admin Panel, and Next.js Storefront

Medusa is released under the MIT license. Discord Chat Follow @medusajs

📌 Project Overview

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.


🏗️ Project Structure

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

🧠 Architecture Design

This project uses a separation of concerns approach:

  • Source Code Directories:

    • my-medusa-store - Backend Medusa application generated with create-medusa-app
    • my-medusa-store-storefront - Storefront Next.js application
  • Docker Configuration Directories:

    • backend/ - Contains Dockerfile for Medusa backend
    • admin/ - Contains Dockerfile for admin panel
    • storefront/ - 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.

🚀 Getting Started

Requirements

  • Docker and Docker Compose installed on your system
  • Git

Development Setup

  1. Clone the repository:
git clone https://github.com/yourusername/store-medusa-docker.git
cd store-medusa-docker
  1. Build and start the development environment:
docker compose up --build

After the initial build, you can start the containers without rebuilding:

docker compose up
  1. 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 --build to update your environment.

Seeding Your Medusa Store

Add sample data to your store:

docker exec medusa-server medusa seed -f ./data/seed.json

🔧 Production Deployment

This repository contains Dockerfiles for both development (Dockerfile) and production (Dockerfile.prod).

The production Dockerfiles create optimized images based on your local development progress:

  1. Build and run production containers:
docker compose -f docker-compose.yml -f docker-compose.prod.yml up --build -d
  1. For subsequent runs without rebuilding:
docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d

✨ Key Features

  • 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

🔍 Environment Configuration

Environment Variables

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
    

📚 Resources

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📜 License

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.

Try it out

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

About

This repo is managed by the Medusa Community. Medusa does not provide official support for Docker, but we will accept fixes and documentation. Use at your own risk.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • TypeScript 96.9%
  • JavaScript 2.0%
  • Other 1.1%