0

Suppose I have a webserver and a database server installed on the same common Docker image, Is it possible to run them simultaneously, as if they were running inside the same virtual machine?

Is it running docker run <args> twice the best practice for this use case?

lurscher
  • 25,930
  • 29
  • 122
  • 185
  • 3
    Possible duplicate of [Can I run multiple programs in a Docker container?](http://stackoverflow.com/questions/19948149/can-i-run-multiple-programs-in-a-docker-container) – user2566987 Feb 26 '16 at 19:48

2 Answers2

3

You should not use a single image for your web server and the database. You should use one image for the web server and one for the database.

To run this, you would run your database server and then run your webserver and link it to your database server.

There are many examples on internet. I'll just leave this one here : https://github.com/saada/docker-compose-php-mysql

John
  • 338
  • 2
  • 7
0

According to this stack overflow answer it is perfectly possible to do that via a script that takes charge of starting each of these services

Can I run multiple programs in a Docker container?

Although most people just tell you to micro service everything into multiple different containers. It might well be much more manageable in some cases to have containers that lunch more than one process if you think about cloud deployment where you might want to run multiple web apps each corresponding to a different system test.

So you would have your isolated small hsql db running In server mode followed by your wildly or springboot app and finally your system test by mvn..

If you have all three in one container... Then it is just a matter of choosing in which Jenkins node your all in one container is put to run. Since it packs all within irrespective of any other container and the image size is not monstrous... You are really agile. As an example.

So you have to see what is best for you.

With big dBs like mysql you are often better of running them on an isolated container as a base platform for all other docker containers. With dBs like hsql you can easily afford a db per container.

Community
  • 1
  • 1
99Sono
  • 3,554
  • 27
  • 39