moleculerjs / moleculer

:rocket: Progressive microservices framework for Node.js
https://moleculer.services/
MIT License
6.13k stars 580 forks source link

Docker container exits immediately after startup is done #320

Closed mKeRix closed 6 years ago

mKeRix commented 6 years ago

Prerequisites

Expected Behavior

The container running the moleculer app keeps running after startup.

Current Behavior

The container starts, but then exits immediately. Example logs:

greeter_1  | [2018-07-09T19:46:41.419Z] INFO  48b63962f32f-16/BROKER: Moleculer v0.12.8 is starting...
greeter_1  | [2018-07-09T19:46:41.422Z] INFO  48b63962f32f-16/BROKER: Node ID: 48b63962f32f-16
greeter_1  | [2018-07-09T19:46:41.423Z] INFO  48b63962f32f-16/BROKER: Namespace: <not defined>
greeter_1  | [2018-07-09T19:46:41.424Z] INFO  48b63962f32f-16/REGISTRY: Strategy: RoundRobinStrategy
greeter_1  | [2018-07-09T19:46:41.436Z] INFO  48b63962f32f-16/REGISTRY: '$node' service is registered.
greeter_1  | [2018-07-09T19:46:41.440Z] INFO  48b63962f32f-16/REGISTRY: 'greeter' service is registered.
greeter_1  | [2018-07-09T19:46:41.442Z] INFO  48b63962f32f-16/BROKER: ServiceBroker with 2 service(s) is started successfully.
greeter_1  | [2018-07-09T19:46:41.445Z] INFO  48b63962f32f-16/BROKER: ServiceBroker is stopped successfully. Good bye.
test-moleculer_greeter_1 exited with code 0

Failure Information

The script still works fine when run on the console of the host machine directly. This is not an npm issue, as executing the runner directly yields the same issue. Only fix I found so far is supplying the --instances flag (with 1 worker in my case) to the moleculer runner.

Steps to Reproduce

You can reproduce this with the init project:

moleculer init project test-moleculer
cd test-moleculer
docker-compose up

The options I took:

Template repo: moleculerjs/moleculer-template-project
? Add API Gateway (moleculer-web) service Yes
? Would you like to communicate with other nodes? No
? Would you like to use cache? No
? Add Docker files? Yes
? Use ESLint to lint your code? Yes
? Setup unit tests with Jest? Yes
Create 'test-moleculer' folder...
? Would you like to run 'npm install'? No

Context

These are the versions I could reproduce the error on:

icebob commented 6 years ago

It's normal behaviour because you didn't use any code which uses event loop (e.g. API gateway, or any transporter). If you don't define transporter and there is not any gateway, the services won't be called, so the process will exit.

mKeRix commented 6 years ago

Makes sense - thanks for clearing that up so quickly. :)