How to use docker
This part is about concepts and decision making rather than step by step technical implementations.
Need for docker
The need for dockerization arises when you have:
- Multiple environments (development, staging, production). Docker can help abstracting and create a uniform environment across all stages.
- Microservice architecture. Too many services are hard to handle manually. Docker and especially docker compose can help a lot with that.
- Dependency management. When you need specific and complex dependencies, docker can help abstract from the host system so that it is not necessary to install these dependencies on the host system.
- Team collaboration. Especially in teams, it can be helpful so that people can simply run the container and don't need to install everything on their machine. (this is not necessary if everyone is on macos or linux. However if someone is on windows and others on linux it might be useful.)
When to introduce it
Docker should be introduced early in development. Do not try to deploy your app outside of a docker container. That is wasted time. It should be done before scaling and prior to development.
How to introduce it
- Define which components your app has or should have. (singular purpose etc...)
- Write a dockerfile for each. Try to make them work by themselves for easy development and debugging.
- Use docker compose for multicontainer applications
- Use CI/CD Integration. Automatically building and deploying docker images ensures that your application is always up to date and can be quickly deployed to any environment.
Do not overengineer. Only if the prerequisites are met and it makes sense to dockerize something should you do it. An example is also when you use too many containers for something that could easily be done in one. Not necessarily specific to the usage of docker but more general.
keep your dockerfiles small. By choosing the right base images you can nearly always reduce the size considerably.
There are tools to monitor your docker containers that should be used in production.