Sreehari
Sreehari

Reputation: 1370

Run multiple servers from a docker image

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.

Upvotes: 9

Views: 11061

Answers (4)

user2105103
user2105103

Reputation: 13135

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

Upvotes: 3

Elijah
Elijah

Reputation: 13604

You may want to check out the phusion passenger nodejs image. You can configure it to run a single server that is serving data from multiple nodejs processes.

Upvotes: 0

Shibashis
Shibashis

Reputation: 8421

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.

Upvotes: 6

Ethan Mott
Ethan Mott

Reputation: 187

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.

Upvotes: 5

Related Questions