skip to Main Content

We have several sites running under a CMS using virtual machines. Basically we have three VM running the CMS and a SQL instance to store data. We plan to transition to containers, but to be honest I’m don’t have much idea about it and my boss plans to have the full app (CMS and DB) within an image and then deploy as many containers as needed (initially three). My doubt here is that as far as I know containers work better separating the different parts and using them as microservices, so I don’t know if it’s a good idea to have the full app within the container.

3

Answers


  1. Short answer is: No.

    It’s best practice with containers to have one process per container. The container has an entrypoint, basically a command that is executed when starting the container. This entrypoint will be the command that starts your process. If you want more than one process, you need to have a script in the container that starts them and puts them in the background, complicating the whole setup. See also docker docs.

    There are some more downsides.

    1. A container should only consist of everything it needs to run the process. If you have more than one process, you’ll have one big container. Also your not independent on the base image, but you need to find one, that fits all processes you want to run. Also you might have troubles with dependencies, because the different processes might need different version of a dependency (like a library).

    2. You’re unable to scale independently. E.g. you could have 5 CMS container that all use the same database, for redundance and performance. That’s not possible when you have everything in the same container.

    3. Detecting/debugging fault. If more than one process runs in a container, the container might fail because one of the processes failed. But you can’t be sure which one. If you have one process and the container fails, you know exactly why. Also it’s easier to monitor health, because there is one health-check endpoint for that container. Last but not least, logs of the container represent logs of the process, not of multiple ones.

    4. Updating becomes easier. When updating your CMS to the next version or updating the database, you need to update the container image of the process. E.g. the database doesn’t need to be stopped/started when you update the CMS.

    5. The container can be reused easier. You can e.g. use the same container everywhere and mount the customer specifics from a volume, configmap or environment variable.

    If you want both your CMS and database together you can use the sidecar pattern in kubernetes. Simply have a pod with multiple containers in the manifest. Note that this too will not make it horizontal scalable.

    Login or Signup to reply.
  2. It’s not clear what you mean with CMS (content/customer/… management system). Nonetheless, milestones on the way to create/sepearte an application (monolith/mcsvs) would propably be:

    • if the application is a smaller one, start with a monolithic structure (whole application as an executable on a application/webserver
    • otherwise determine which parts should be seperated (-> Domain-Driven Design)
    • if the smaller monolithic structure is getting bigger and you put more domain related services, you pull it apart with well defined seperations according to your domain landscape:

    Once you have a firm grasp on why you think microservices are a good
    idea, you can use this understanding to help prioritize which
    microservices to create first. Want to scale the application?
    Functionality that currently constrains the system’s ability to handle
    load is going to be high on the list. Want to improve time to market?
    Look at the system’s volatility to identify those pieces of
    functionality that change most frequently, and see if they would work
    as microservices. You can use static analysis tools like CodeScene to
    quickly find volatile parts of your codebase.

    "Building Microservices"-S.Newman

    Database

    According to the principle of "hiding internal state", every microservice should have its own database.

    If a microservice wants to access data held by another microservice,
    it should go and ask that second microservice for the data. … which allows us to clearly separate functionality

    In the long run this could be perfected into completely seperated end-to-end slices backed by their own database (UI-LOGIC-DATA). In the context of microservices:

    sharing databases is one of the worst things you can do if you’re trying to achieve independent deployability

    So the general way of choice would be more or less:

    enter image description here

    Login or Signup to reply.
  3. That’s a fair question that most of us go through at some point. One tends to have everything in the same container for convenience but then later regret that choice.

    So, best to do it right from the start and to have one container for the app and one for the database.

    According to Docker’s documentation,

    Up to this point, we have been working with single container apps. But, we now want to add MySQL to the application stack. The following question often arises – “Where will MySQL run? Install it in the same container or run it separately?” In general, each container should do one thing and do it well.

    (…)

    So, we will update our application to work like this:

    Why one should have one container for the app and another for the database

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search