Docker Community Forums

Share and learn in the Docker community.

Multiple containers for one rails app?


(Nroose) #1

I am a Ruby on Rails developer. Currently I use virtual machines to make it so that I can work on more than one separate bug/feature at the same time, on different git branches. Is there a good way to do that using docker? I gather than most who are talking about rails development with docker, they seem to have the code locally and run it in a container with the code synced or mounted in some way. I would have 3 or so different branches of the code that I am working on. I am planning on trying to have a compose file with multiple rails app directories underneath it that I put in different docker containers that share a mysql db in it’s own container. Does that make sense?


(Eric Ongerth) #2

Yes, that makes sense as long as it truly serves your intended purpose.

When you say “they seem to have the code locally and run it in a container with the code synced or mounted in some way” – yes, they are using a bind mount (see docker or docker-compose docs regarding how to declare data volumes) or an add-on sync solution such as docker-sync.io. (side note, don’t try to bind mount on docker-for-windows, as of this writing, IMO; there have been persistent permissions/ownership issues and it’s specifically a docker-for-windows problem.)

If I’m interpreting your question correctly, you wish to keep your mysql db running just the same regardless of it being accessed by your various different branches of rails app code that you are working on. I trust you have thought about the possibilities of introducing difficult situations in your data consistency or your data being in or out of sync with some type of app state, in the various branches of your code, unless your app is truly stateless (in which case, kudos for that). Other than that possible issue, there’s no reason you can’t set things up so that all of them are able to access the same mysql container and just keep that db container running even while you build and break down the other containers repeatedly at will.

You may need to think about whether you really want the various development branches of your app, in their own containers, to access the mysql db all using the same user. I mean, there’s no technical reason why you couldn’t, but I can think of some reasons why it could make debugging harder for you. I’m not saying this is a must, but maybe you’d want to give each branch a different db user just so you can track things. Maybe even a separate copy of the database (although at that point you’d find that docker containers being so incredibly slim and fast to spin up, you could so easily just have a separate mysql db container for each branch). Which brings me back to thinking you may have your own reasons for wanting the separate dev branches of your app to actually interact with a dataset that has been built up incrementally by all of the various branches. I don’t know why but maybe that’s what you want. Your call.

And compared to your current approach of using full VMs for this, yes, docker will save you quite a lot of time since containers are so lightweight and fire up and down so trivially. It’s fun.