{"id":28436878,"url":"https://github.com/moleculerjs/docker-demo","last_synced_at":"2025-06-27T20:32:11.821Z","repository":{"id":46934532,"uuid":"193219392","full_name":"moleculerjs/docker-demo","owner":"moleculerjs","description":"Kubernetes \u0026 Docker demo for Moleculer project testing \u0026 prototyping.","archived":false,"fork":false,"pushed_at":"2023-02-06T18:25:09.000Z","size":532,"stargazers_count":17,"open_issues_count":0,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-05T23:07:52.452Z","etag":null,"topics":["docker","docker-demo","kubernetes","moleculer"],"latest_commit_sha":null,"homepage":"https://hub.docker.com/r/moleculer/demo","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/moleculerjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-06-22T10:07:48.000Z","updated_at":"2023-10-25T17:48:42.000Z","dependencies_parsed_at":"2022-09-23T09:23:29.087Z","dependency_job_id":"9abfac75-67f8-4f45-86df-31eaef5cfaec","html_url":"https://github.com/moleculerjs/docker-demo","commit_stats":{"total_commits":71,"total_committers":3,"mean_commits":"23.666666666666668","dds":0.04225352112676062,"last_synced_commit":"8625730163e1a6661759c49f9124ad89b4b9408a"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/moleculerjs/docker-demo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moleculerjs%2Fdocker-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moleculerjs%2Fdocker-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moleculerjs%2Fdocker-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moleculerjs%2Fdocker-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moleculerjs","download_url":"https://codeload.github.com/moleculerjs/docker-demo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moleculerjs%2Fdocker-demo/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260961635,"owners_count":23089255,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","docker-demo","kubernetes","moleculer"],"created_at":"2025-06-05T23:07:51.036Z","updated_at":"2025-06-27T20:32:11.068Z","avatar_url":"https://github.com/moleculerjs.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Moleculer logo](http://moleculer.services/images/banner.png)\n\n[![Moleculer](https://badgen.net/badge/Powered%20by/Moleculer/0e83cd)](https://moleculer.services)\n\n# Demo project for Docker\nThis is an example project to try Moleculer with Docker and Kubernetes.\n\n# Usage with Docker\n\n## Run a container with all services\n\n```bash\ndocker run -e SERVICES=services -p 3000:3000 moleculer/demo\n```\n\n## Run every services in an individual container\nIn this case you should also start a transporter, e.g. NATS.\n```bash\ndocker run -d -e SERVICEDIR=services -e SERVICES=greeter moleculer/demo\ndocker run -d -e SERVICEDIR=services -e SERVICES=products moleculer/demo\ndocker run -d -e SERVICEDIR=services -e SERVICES=api -p 3000:3000 moleculer/demo\n```\n\n# Usage with Docker Compose\nThis command starts all services in individual containers, a NATS server as transporter, a MongoDB server \u0026 Traefik as reverse proxy.\n```bash\ndocker-compose up -d\n```\n\n# Usage with Docker Swarm\nThis command starts all services in individual containers, a NATS server as transporter, a MongoDB server \u0026 Traefik as reverse proxy.\n```bash\ndocker stack deploy -c docker-compose.yml moleculer\n```\n\n# Usage with Kubernetes\nThis command starts all services in individual pods, a NATS server as transporter, a MongoDB server and register an ingress for API service via http://moleculer.127.0.0.1.nip.io/ URL.\n```bash\nkubectl apply -f https://raw.githubusercontent.com/moleculerjs/docker-demo/master/k8s.yaml\n```\n\n**Result**\n```\nNAME                                           READY   STATUS    RESTARTS   AGE\npod/nats-6c745f949b-8g994                      1/1     Running   0          23h\npod/moleculer-demo-api-6958b5475b-5qfxx        1/1     Running   0          4h37m\npod/moleculer-demo-greeter-6c875544b6-jbcjf    1/1     Running   0          4h37m\npod/moleculer-demo-greeter-6c875544b6-fx829    1/1     Running   0          4h37m\npod/moleculer-demo-api-6958b5475b-mwbc8        1/1     Running   0          4h36m\npod/mongo-555c4f494f-xjvx8                     1/1     Running   0          3h15m\npod/moleculer-demo-products-784446b876-fdlrz   1/1     Running   0          3h8m\npod/moleculer-demo-products-784446b876-5qfrc   1/1     Running   0          3h8m\n\nNAME            TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)     AGE\nservice/nats    ClusterIP   10.43.193.134   \u003cnone\u003e        4222/TCP    23h\nservice/api     ClusterIP   10.43.121.57    \u003cnone\u003e        3000/TCP    22h\nservice/mongo   ClusterIP   10.43.80.140    \u003cnone\u003e        27017/TCP   3h15m\n\nNAME                                      READY   UP-TO-DATE   AVAILABLE   AGE\ndeployment.apps/nats                      1/1     1            1           23h\ndeployment.apps/moleculer-demo-greeter    2/2     2            2           23h\ndeployment.apps/moleculer-demo-api        2/2     2            2           23h\ndeployment.apps/mongo                     1/1     1            1           3h15m\ndeployment.apps/moleculer-demo-products   2/2     2            2           4h37m\n\nNAME                                                 DESIRED   CURRENT   READY   AGE\nreplicaset.apps/nats-6c745f949b                      1         1         1       23h\nreplicaset.apps/moleculer-demo-greeter-6c875544b6    2         2         2       4h37m\nreplicaset.apps/moleculer-demo-api-6958b5475b        2         2         2       4h37m\nreplicaset.apps/mongo-555c4f494f                     1         1         1       3h15m\nreplicaset.apps/moleculer-demo-products-784446b876   2         2         2       3h8m\n```\n\n\u003eIf you don't have installed ingress controller, [execute this script](https://gist.github.com/icebob/2fae81d90cda3740e4f41e6080a29632) to install Nginx Ingress Controller.\n\n\u003eIf you don't have installed storage controller, [execute this script](https://gist.github.com/icebob/fa969c7696269d72a4e6e8378f9f9595) to install [Longhorn Storage Controller](https://github.com/longhorn/longhorn).\n\n# Services\n- **api**: API Gateway services\n- **calc**: Sample service with heavy mathematical calculation to test auto scaling of K8s.\n- **greeter**: Sample service with `hello` and `welcome` actions.\n- **products**: Sample DB service with MongoDB if `process.env.MONGO_URI` is defined, otherwise with NeDB.\n\n# Test the running project\nIn case of Docker or Docker Compose\n```\nexport HOSTNAME=127.0.0.1:3000\n```\n\nIn case of Kubernetes\n```\nexport HOSTNAME=moleculer.127.0.0.1.nip.io\n```\n\n**Call the `greeter.hello` action**\n```bash\ncurl http://$HOSTNAME/api/hello\n```\n\n**Call the `greeter.welcome` action with params**\n```bash\ncurl http://$HOSTNAME/api/greeter/welcome?name=Moleculer\n```\n\n**Create a product item**\n```bash\ncurl -X POST -H \"Content-Type: application/json\" -d '{\"name\": \"Samsung Galaxy S10\", \"category\": \"phones\", \"price\": 299.99, \"quantity\": 10}' http://$HOSTNAME/api/products\n```\n\n**List all products**\n```bash\ncurl http://$HOSTNAME/api/products\n```\n\n# Connect from CLI\n1. Port forwarding the NATS service port\n\t```bash\n\tkubectl port-forward --address 0.0.0.0 service/nats 4222\n\t```\n\t\u003eIf you have firewall, don't forget to allow this port.\n2. Connect to the deployed application from Moleculer CLI\n\t```bash\n\tmoleculer connect nats://\u003cYOUR-CLUSTER-IP-ADDRESS\u003e:4222\n\t```\n\n# Horizontal Pod Auto Scaling\nThe deployment script contains a [HorizontalPodAutoscaler](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/) definition for the `calc` service. It scales the number of `calc` service pod between 2 and 5 by CPU usages.\n\n**Benchmark the `calc.pi` action to increase the CPU usages to trigger the K8s Horizontal Pod Autoscaler:**\n```bash\nab -c 5 -n 500 http://moleculer.127.0.0.1.nip.io/api/pi\n```\n\n# License\nThis project is available under the [MIT license](https://tldrlegal.com/license/mit-license).\n\n# Contact\nCopyright (c) 2016-2020 MoleculerJS\n\n[![@moleculerjs](https://img.shields.io/badge/github-moleculerjs-green.svg)](https://github.com/moleculerjs) [![@MoleculerJS](https://img.shields.io/badge/twitter-MoleculerJS-blue.svg)](https://twitter.com/MoleculerJS)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoleculerjs%2Fdocker-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoleculerjs%2Fdocker-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoleculerjs%2Fdocker-demo/lists"}