119: Optimization and Refactoring of Docker and Docker Compose Network Modes



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.


Based on our existing docker-compose.yml file (see attached), there are areas that can be potentially improved in terms of networking:

  1. 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.
  2. 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.
  3. Dependency Management: While depends_on is used, we might want to look into the use of wait-for-it or similar scripts to ensure services are fully up and ready before dependants start.
  4. 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:

  1. Evaluate the current bridge mode against our application's needs. Consider if host, overlay, or macvlan modes might be more appropriate.
  2. Investigate using Docker's native DNS for service discovery rather than hardcoding IP addresses.
  3. Implement wait-for-it or similar scripts for better management of service dependencies.
  4. Ensure all services have consistent network configurations, including necessary settings for IPv4 and IPv6 (if applicable).
  5. Update and refactor the docker-compose.yml file based on the findings and proposed changes.