Docker deployment of background services

With the scripts we've written so far, the Docker container is run in the foreground.  That makes it easier to debug the service since you see the errors.   For a production deployment, we need the Docker container detached from the terminal, and an assurance that it will restart itself automatically.   Those two attributes are simple to implement.

Simply change this pattern:

$ docker run -it ...

To this pattern:

$ docker run --detach --restart always ...

The -it option is what causes the Docker container to run in the foreground.  Using these options causes the Docker container to run detached from your terminal, and if the service process dies, the container will automatically restart.

Get Node.js Web Development - Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.