119: Optimization and Refactoring of Docker and Docker Compose Network Modes
Description:
Background:
Our current Docker and Docker Compose setups use a bridge network mode. However, there's a need to optimize and refactor the network modes for better scalability, maintainability, and performance.
Issue:
Based on our existing docker-compose.yml
file (see attached), there are areas that can be potentially improved in terms of networking:
- Use of Bridge Mode: While bridge mode is a default and often suitable for many applications, there might be scenarios where host or overlay networking modes may offer better performance or more suitable isolation.
- Network Addressing: Hardcoding IP addresses (e.g.,
${MYSQL_NETWORK_ADDRESS}
,${MONGO_NETWORK_ADDRESS}
, etc.) may not be scalable. We need a more dynamic way of handling this. - Dependency Management: While
depends_on
is used, we might want to look into the use ofwait-for-it
or similar scripts to ensure services are fully up and ready before dependants start. - Consistency: Ensure that the network configurations are consistent across all services. For instance, all services should be part of the necessary networks, and network mode should be uniform unless there's a valid reason for deviations.
Proposed Action:
- Evaluate the current bridge mode against our application's needs. Consider if host, overlay, or macvlan modes might be more appropriate.
- Investigate using Docker's native DNS for service discovery rather than hardcoding IP addresses.
- Implement
wait-for-it
or similar scripts for better management of service dependencies. - Ensure all services have consistent network configurations, including necessary settings for IPv4 and IPv6 (if applicable).
- Update and refactor the
docker-compose.yml
file based on the findings and proposed changes.