Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restart Node on a docker container without restarting the whole container?

I have a container ==> FROM node:5 Node should restart after each change in the code.

But there is no way for me restart the Node server without restarting the whole docker container.

I have many npm install on dockerfile that runs each time I restart the container, and it's annoying to wait for all of them after each change in the code.

I'm already using shared folder to have the latest code in my container.

like image 641
DaNeSh Avatar asked May 19 '16 16:05

DaNeSh


People also ask

Does restarting docker restart all containers?

For a major version upgrade, one has to tear down all running containers. With a restart policy of always , however, the containers will be restarted after the docker daemon is restarted after the upgrade.

How do I restart docker without stopping containers?

On Linux, you can avoid a restart (and avoid any downtime for your containers) by reloading the Docker daemon. If you use systemd , then use the command systemctl reload docker . Otherwise, send a SIGHUP signal to the dockerd process.

Does restarting docker stop containers?

A reload will not impact your containers, unlike a full daemon restart. Live restore should now be activated. You can test it out by stopping the Docker daemon.


1 Answers

If you just need the Node.js server to restart after changes, instead of starting the server with the node command you can use a tool like node-dev or nodemon. To leverage these, you'd need to update the command in your Dockerfile, e.g. CMD [ "node-dev", "server.js" ].

Since you already have your local files as a volume in the Docker container, any change to those files will restart the server.

like image 147
Nick Bernard Avatar answered Nov 15 '22 05:11

Nick Bernard