0

I have an app called A that uses MongoDB for state. My plan is to use Docker and perhaps create one container for the app and one for MongoDB and then link A with MongoDB (possibly using fig). From what I understand I ought to use a data volume or "data-only containers" for MongoDB state. But if I understand it correctly you link to an image (MongoDB image in this case). Does this mean that I need to restart MongoDB when I deploy a new version of A?

What I want to do is to deploy changes to A (A') without loosing MongoDB state and (possibly) without taking MongoDB down. Without Docker I would just bring A down and deploy A' and have it connect to the same MongoDB instance (that would still be running). This is especially important if I run multiple instances of A behind a load balancer. How would I achieve this in a good way using the Docker infrastructure? Is linking only a good option if I run a single instance of A?

Johan
  • 37,479
  • 32
  • 149
  • 237
  • Having a database run inside a docker container is a bit sketchy, rather have App A run inside a docker container and run your DB outside a docker container. – Jan Vladimir Mostert Dec 29 '14 at 07:48
  • Why is that? I see a lot of examples on the net of databases inside Docker? (Mongo, MySQL, Redis just to name a few) – Johan Dec 29 '14 at 11:12
  • 1
    If I may quote some of the lead engineers at Google and Red Hat and some private consulting architects I've spoken to, if you want to sleep peacefully at night, don't put your data/db inside docker. For experimentation it's fine, for production, it's easy to lose data when you kill a container or corrupt a db when you stop a container. If you really want to run your db in a docker container, at least mount a volume so that the data sits outside the container, it would be very easy to lose data otherwise. – Jan Vladimir Mostert Dec 29 '14 at 12:33
  • possible duplicate of [How to deal with persistent storage (e.g. databases) in docker](http://stackoverflow.com/questions/18496940/how-to-deal-with-persistent-storage-e-g-databases-in-docker) – Bryan Dec 31 '14 at 09:38

1 Answers1

3

You would need to restart MongoDB and/or data containers only if they are linked to container A. So in your case, the steps I would follow:

  1. Start your 'Data Volume Container' with a volume mounted for the data.
  2. Start your MongoDB container(s), using the docker option --volumes-from to have access to the data of the first container.
  3. Start your application container A, linking to the MongoDB container(s).

There is no need of restarting the data or MongoDB containers because they are not linked directly to your container application.

Javier Cortejoso
  • 8,851
  • 3
  • 26
  • 27