akc42
akc42

Reputation: 5001

In Docker Compose can I have services exiting

I am trying to use Docker Compose to build a series of services that make up a web server and its components and then make them live. However, some of the "services" I want there are just to create "Volumes" to populate directories such as node_modules, or bower_components. This allows me to have much more control over the versioning of things.

What I can't find out is what happens to these services if they exit (with exit(0)). Does the remainder of the services keep running successfully.

I "could" perhaps have a small task which just waits for the sigint like so:-

(function() {
  'use strict';
  process.on('SIGINT', function() {
    process.exit(0);    
  });
})();

but this seems like a bit of a fudge.

Upvotes: 0

Views: 96

Answers (1)

BlackStork
BlackStork

Reputation: 8331

If your service is up just do certain job and die why instead of letting them to hang till you manually kill them, just not monitor them via docker-compose logs -f ${service} / using stdout/stderr of their specific containers? Docker-compose streams logs into specific container-bound log file, and you can access to its data both via docker-compose cli, docker API, readable file stream and what else. While majority of theese could be overkill for your case - using docker-compose logs -f is very convinient method to get container-specific activity report.

Still if you really want to keep them alive you can create npm script (via package.json) that will attach signal event handler as you wrote from specific file. You can add such command to the service command

     command: sh -c 'do your stuff; npm run wait-signal-server'

You can use plain js file and just use it via node file.js but using/ running as npm scripts is more convenient way for such things - in my oppinion

Upvotes: 1

Related Questions