You are viewing documentation for a beta release that is currently undergoing final testing before its official release. 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.
The Docker files shown here are from moleculer-demo project.
For mode detailed info about Docker and Kubernetes please check the docker demo repository.
Dockerfile
Dockerfile to run Moleculer services
FROM node:current-alpine
ENV NODE_ENV=production
RUN mkdir /app WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install --production
COPY . .
CMD ["npm", "start"]
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 moleculer runner about the location of service files
TRANSPORTER=nats://nats:4222 # Set transporter in all containers MONGO_URI=mongodb://mongo/project-demo # Set MongoDB URI
Configure the containers. docker-compose.yml
version:"3.3"
services:
api: build: context:. image:project-demo env_file:docker-compose.env environment: SERVICES:api# Moleculer Runner will start only the 'api' service in this container PORT:3000# Port of API gateway depends_on: -nats labels: -"traefik.enable=true" -"traefik.http.routers.api-gw.rule=PathPrefix(`/`)" -"traefik.http.services.api-gw.loadbalancer.server.port=3000" networks: -internal
greeter: build: context:. image:project-demo env_file:docker-compose.env environment: SERVICES:greeter# Moleculer Runner will start only the 'greeter' service in this container depends_on: -nats networks: -internal
products: build: context:. image:project-demo env_file:docker-compose.env environment: SERVICES:products# Moleculer Runner will start only the 'products' service in this container depends_on: -mongo -nats networks: -internal