Add a new service to existing Docker configuration
Adds new services like databases, caches, or queues to Docker Compose configuration with environment files.
/plugin marketplace add adelabdelgawad/full-stack/plugin install docker-stack@full-stackIMPORTANT: When this command is invoked, you MUST actually MODIFY the docker-compose files and CREATE necessary files. Do NOT just describe what to add.
Parse the user's request to determine:
Use Read tool to examine:
docker/docker-compose.prod.yml - to add the servicedocker/docker-compose.yml (if exists) - for dev config # Add to services:
database:
image: postgres:15-alpine
container_name: {{PROJECT_NAME}}-postgres
restart: unless-stopped
ports:
- "5432:5432"
env_file:
- ./env/.env.database
volumes:
- postgres_data:/var/lib/postgresql/data
networks:
- {{PROJECT_NAME}}-network
deploy:
resources:
limits:
cpus: '2'
memory: 2G
reservations:
cpus: '1'
memory: 1G
healthcheck:
test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
# Add to volumes:
postgres_data:
driver: local
database:
image: mongo:7.0
container_name: {{PROJECT_NAME}}-mongo
restart: unless-stopped
ports:
- "27017:27017"
env_file:
- ./env/.env.database
volumes:
- mongo_data:/data/db
networks:
- {{PROJECT_NAME}}-network
deploy:
resources:
limits:
cpus: '2'
memory: 2G
healthcheck:
test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
# Add to volumes:
mongo_data:
driver: local
rabbitmq:
image: rabbitmq:3.12-management-alpine
container_name: {{PROJECT_NAME}}-rabbitmq
restart: unless-stopped
ports:
- "5672:5672"
- "15672:15672"
env_file:
- ./env/.env.rabbitmq
volumes:
- rabbitmq_data:/var/lib/rabbitmq
networks:
- {{PROJECT_NAME}}-network
deploy:
resources:
limits:
cpus: '1'
memory: 1G
healthcheck:
test: ["CMD", "rabbitmq-diagnostics", "check_running"]
interval: 30s
timeout: 10s
retries: 5
start_period: 30s
# Add to volumes:
rabbitmq_data:
driver: local
memcached:
image: memcached:1.6-alpine
container_name: {{PROJECT_NAME}}-memcached
restart: unless-stopped
ports:
- "11211:11211"
command: memcached -m 256
networks:
- {{PROJECT_NAME}}-network
deploy:
resources:
limits:
cpus: '0.5'
memory: 512M
healthcheck:
test: ["CMD", "nc", "-z", "localhost", "11211"]
interval: 10s
timeout: 5s
retries: 3
elasticsearch:
image: elasticsearch:8.12.0
container_name: {{PROJECT_NAME}}-elasticsearch
restart: unless-stopped
ports:
- "9200:9200"
environment:
- discovery.type=single-node
- xpack.security.enabled=false
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
volumes:
- elasticsearch_data:/usr/share/elasticsearch/data
networks:
- {{PROJECT_NAME}}-network
deploy:
resources:
limits:
cpus: '2'
memory: 2G
healthcheck:
test: ["CMD-SHELL", "curl -s http://localhost:9200/_cluster/health | grep -q 'green\\|yellow'"]
interval: 30s
timeout: 10s
retries: 5
start_period: 60s
# Add to volumes:
elasticsearch_data:
driver: local
CREATE the environment template file:
POSTGRES_USER={{project}}_user
POSTGRES_PASSWORD=CHANGE_ME_IN_PRODUCTION
POSTGRES_DB={{project}}_db
MONGO_INITDB_ROOT_USERNAME=admin
MONGO_INITDB_ROOT_PASSWORD=CHANGE_ME_IN_PRODUCTION
MONGO_INITDB_DATABASE={{project}}_db
RABBITMQ_DEFAULT_USER=admin
RABBITMQ_DEFAULT_PASS=CHANGE_ME_IN_PRODUCTION
RABBITMQ_DEFAULT_VHOST=/
If adding a database/cache that backend depends on, UPDATE the backend service:
backend-1: # and backend-2, backend-3
depends_on:
database: # or new_service name
condition: service_healthy
If backend needs to connect to the new service, ADD variables to .env.example.backend:
# For PostgreSQL
DATABASE_URL=postgresql://{{project}}_user:password@database:5432/{{project}}_db
# For RabbitMQ
CELERY_BROKER_URL=amqp://admin:password@rabbitmq:5672//
# For MongoDB
MONGODB_URL=mongodb://admin:password@database:27017/{{project}}_db
After making changes, output:
✅ Service added successfully!
Added service: {service_name}
Image: {image}:{version}
Files modified:
- docker/docker-compose.prod.yml (added service + volume)
- docker/env/.env.example.{service} (created)
- docker/env/.env.example.backend (updated with connection vars)
Service details:
- Port: {port}
- Volume: {volume_name}
- Health check: configured
Next steps:
1. Copy env template: cp docker/env/.env.example.{service} docker/env/.env.{service}
2. Update credentials in .env.{service}
3. Restart stack: docker-compose -f docker/docker-compose.prod.yml up -d
This command MUST:
DO NOT just show YAML snippets. ACTUALLY MODIFY THE FILES.