I am not sure what's the best practice of using the docker container. When I use VM, say ubuntu, for running a web application, I install every software I need to run the application such as database, web services, etc and use like a standalone operating system.
However, Docker can be used in a different way.
Given a scenario that I want to run a web application, I have two option:
Install all softwares on one container; install database, java, and all other necessary softwares needed to run (i.e. use just like how I would use VM).
Install each application on a separate containers; database in one container, web service on other container, and make them talk to each other.
The option 1) seems to be easier to deploy a full-stacked application but may be harder to scale if there are some dependency complication issues between packages or allocating OS resources to each software.
The option 2) seems to be harder to deploy but each container can be upgraded without too much pain.
What's the common practice among Docker users?
Edit: Answer to this is also noted in https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/#run-only-one-process-per-container
The best way is to use a separate container for each service (application). In this way you can upgrade/modify each service independently from the other containers. Docker works really nice for the micro service architecture.
Use Docker Compose for running all containers with just one command: docker-compose up. In Docker Compose you can define dependencies among containers. So, they will connect automatically.
If you wanna run every container on a separate Linux host, you can use Docker Swarm in order that you don't have to care about networking.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With