mysql - Running migrations with Rails in a Docker container with multiple container instances -


i've seen lots of examples of making docker containers rails applications. typically run rails server , have cmd runs migrations/setup brings rails server.

if i'm spawning 5 of these containers @ same time, how rails handle multiple processes trying initiate migrations? can see rails checking current schema version in general query log (it's mysql database):

 select `schema_migrations`.`version` `schema_migrations` 

but can see race condition here if happens @ same time on different rails instances.

considering ddl not transactional in mysql , don't see locks happening in general query log while running migrations (other per-migration transactions), seem kicking them off in parallel bad idea. in fact if kick off 3 times locally can see 2 of rails instances crashing when trying create table because exists while third rails instance completes migrations happily. if migration inserted database quite unsafe.

is better idea run single container runs migrations/setup spawns (for example) unicorn instance in turn spawns multiple rails workers?

should spawning n rails containers , 1 'migration container' runs migration exits?

is there better option?

especially rails don't have experience, let's docker , software engineering point of view.

the docker team advocates, quite aggressively, containers shipping applications. in this great statement, jerome petazzoni says separation of concerns. feel point figured out.

running rails container starts migration or setup might initial deployment , required during development. however, when going production, should consider separating concerns.

thus have 1 image, use run n rails container , add tools/migration/setup whatever container, use administrative tasks. have developers official rails image this:

it designed used both throw away container (mount source code , start container start app), base build other images off of.

when @ image there no setup or migration command. totally user how use it. when need run several containers go ahead.

from experience mysql works fine. can run data-only container host data, run container mysql server , run container administrative tasks backup , restore. 3 containers can use same image. free access database let's several wordpress containers. means clear separation of concerns. when use docker-compose not difficult manage containers. there many third party containers , tools support setting complex application consisting of several containers.

finally, should decide whether docker , micro-service architecture right problem. outlined in this article there reasons against. 1 of core problems being adds whole new layer of complexity. however, case many solutions , guess aware of , willing except it.


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -