Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build stateful docker services architecture with CoreOS's fleet?

Tags:

docker

coreos

CoreOS used with fleet enables one to build services running some docker applications.

But is there any way to run docker services which require its state to be kept between restarts, to be persistent? For instance, databases or services that must store some files to be shared later on.

Because as far as I know, the service can be launched on core-1 machine (for example), and on restart will be launched on another one randomly. So the docker volume can be lost.

like image 910
Anthony O. Avatar asked Aug 18 '14 09:08

Anthony O.


2 Answers

The simplest way to maintain a database service is to always schedule the fleet unit to the same machine. You can do this by adding an [X-Fleet] section to the fleet unit file and either assigning the unit to a particular X-ConditionMachineID, or X-ConditionMachineMetadata. See the coreos documentation.

You can then persist data outside your docker containers by mounting a volume from the host machine. The recommended way of doing this is to wrap this data in a separate data container via docker:

docker run --name mongodb-volume -v /home/core/mongodb-data:/data/db busybox docker run -p 27017 --volumes-from mongodb-volume mongodb:latest

Since /home/core/mongodb-data on a particular machine will store persistent mongodb state and the unit will always be scheduled to that same machine, this will solve your problem.

like image 67
jkingyens Avatar answered Oct 15 '22 20:10

jkingyens


You can consider to run some distributed filesystem over CoreOS cluster. This way whatever machine your database service container ends on, it will always be able to use database, mounted from DFS.

like image 34
Vladislav Rastrusny Avatar answered Oct 15 '22 18:10

Vladislav Rastrusny