Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 784
Sreehari Avatar asked Jul 27 '16 17:07

Sreehari


3 Answers

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.

like image 85
Ethan Mott Avatar answered Oct 16 '22 22:10

Ethan Mott


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.

like image 39
Shibashis Avatar answered Oct 16 '22 21:10

Shibashis


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

like image 3
user2105103 Avatar answered Oct 16 '22 22:10

user2105103