What is the correct posture for docker?

  docker, question

At present, the use and understanding of docker are a little confused, I would like to ask you a few questions.

For example:
I now have a linux system with 8G memory.
I need to run two environments on this system: alpha and beta.
Alpha and beta environments use their own nginx and mysql.

My current understanding is that there are two options:

Option 1:

Create two containers: container _ alpha, container _ beta.
 Mysql and nginx are installed in both container_alpha and container_beta and inside

Option 2:

Create four containers and * * install only * * in all four containers
 alpha_mysql
 alpha_nginx
 beta_mysql
 beta_nginx

For the scheme, configuration, use and management will be much more convenient and clear.
For scheme 2, each container corresponds to only one service. I wonder if this is more in line with docker’s principle.

Or my understanding of docker is still not correct, so what is the correct posture of using docker?

It depends on what you regard as a service, or “management unit.”

If db+nginx+php is always one-to-one and bound to each other, I think it’s not too bad to treat these as a service.

If the database has master-slave and separation of reading and writing, it will be more convenient to calculate mysql as a service.

In addition, Scheme 2 is more friendly to expansion. If you want to change it, you don’t need to disassemble image, just change docker-compose or other configurations.