LuckyLuke
LuckyLuke

Reputation: 49077

Multiple docker containers

I am reading about docker and I am trying to understand whether or not this is something I should learn to use.

From what I read best practices states that you should have one process per container. Now, this mean that I need one container for JBoss, one for database, one for file storage, build server, ...

Now would I manually have to start each of these containers? Or are there some kind of dependencies you can set up?

What about the order and requirements that one process in a container can have? JBoss needs the database to be started before it starts etc?

Is this handled?

Upvotes: 3

Views: 1325

Answers (1)

Thomasleveil
Thomasleveil

Reputation: 103955

one process per container

This advice is valid if you want to follow a microservices architecture. microservices have advantages but also drawbacks. Depending on your situation you might find it more convenient to have a container running multiple processes.

Running multiple containers on one single host

If you want to start multiple containers together on one single docker host, the easiest way is to use fig. The fig configuration file is very easy to understand as its syntax mimics docker commands. This video gives you a nice presentation of fig (by one of fig authors Aanand Prasad)

Note that tools such as fig AFAIK won't be able to wait for a first container to start and finish initializing before starting another container depending on the first one. The way to handle this is to have the 2nd container implement some kind of test and loop until the dependency is ready, then start its process. This can be achieved by different means (wrapper script, straight in your application code, ...)

Running multiple processes in one container

As a docker container will stop as soon as no process is running in the foreground, there are different techniques you can use (supervisor, running a first process as a daemon and a last one in the foreground, using phusion/baseimage, ...)

Upvotes: 1

Related Questions