This version has reached end-of-life. It is no longer maintained. For the latest stable version, click here.

Deploying

Docker deployment

The example below shows how to use moleculer-runner and Docker to deploy Moleculer services across multiple containers.

Note that moleculer-runner is capable of reading environment variables, which are heavily used in Docker deployments. More info about runner’s configuration loading logic.

The Docker files shown here are from moleculer-demo project.

Dockerfile

Dockerfile to run Moleculer services

FROM node:8-alpine

ENV NODE_ENV=production

RUN mkdir /app
WORKDIR /app

COPY package.json .

RUN npm install --production

COPY . .

CMD ["npm", "start"] # Execute moleculer-runner

Docker Compose

Docker compose files to run Moleculer services with NATS & Traefik (load balancing the API Gateway)

Set the necessary environment variables.
docker-compose.env

NAMESPACE=
LOGGER=true
LOGLEVEL=info
SERVICEDIR=services # Inform runner about the location of service files

TRANSPORTER=nats://nats:4222 # Set transporter in all containers

Configure the containers.
docker-compose.yml

version: "3.2"

services:

api:
build:
context: .
image: moleculer-demo
container_name: moleculer-demo-api
env_file: docker-compose.env
environment:
SERVICES: api # Runner will start only the 'api' service in this container
PORT: 3000 # Port of API gateway
depends_on:
- nats
labels:
- "traefik.enable=true"
- "traefik.backend=api"
- "traefik.port=3000"
- "traefik.frontend.entryPoints=http"
- "traefik.frontend.rule=PathPrefix:/"
networks:
- internal

greeter:
build:
context: .
image: moleculer-demo
container_name: moleculer-demo-greeter
env_file: docker-compose.env
environment:
SERVICES: greeter # Runner will start only the 'greeter' service in this container
labels:
- "traefik.enable=false"
depends_on:
- nats
networks:
- internal

nats:
image: nats
labels:
- "traefik.enable=false"
networks:
- internal

traefik:
image: traefik:1.7
container_name: traefik
command:
- "--api"
- "--docker"
- "--docker.watch"
labels:
- "traefik.enable=true"
- "traefik.backend=traefik"
- "traefik.port=8080"
ports:
- 3000:80
- 3001:8080
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /dev/null:/traefik.toml
networks:
- internal
- default

networks:
internal:

Start containers

$ docker-compose up -d

Access your app on http://<docker-host>:3000/. Traefik dashboard UI on http://<docker-host>:3001/

Kubernetes deployment

Moleculer community members are working on Kubernetes integration. You can check dkuida‘s step by step tutorial, lehno‘s code samples and tobydeh‘s deployment guide.