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