I have three express servers written on nodejs. These servers are serving different purposes and hence running on different ports.
Eg: app1.js on 8000, app2.js on 5000 and app3.js on 5432.
I want to create a docker image using a docker file and run all these servers. Can we do so? If so, how can we do it? As per my knowledge we can run only one command from docker file.
You may want to look into using Docker Compose.
Each server would have its own Dockerfile and your docker-compose.yml file would define the ports these expose and how they interact.
The suggested mechanism by Ethan is correct for running multiple docker container at once, but does not explain why.
Just to explain a bit further, each docker container can spawn multiple processes (servers), but a docker container needs one of the processes to be in foreground, and docker the container lifecycle typically reflects the lifecycle of the foreground process.
Lot of the benefits of dockerization will be lost when you run all processes in one docker container. And hence it is recommended to have one docker container per process.
While it's not "recommended", sure you can. It's even documented.
Docker and Supervisord
Or you can use Runit
Lately I have been using s6
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With