Skip to content

Conversation

@bmiguelbc16
Copy link
Contributor

Pull Request: Enhance Docker Environment with Intelligent Port Detection and Dynamic Container Naming

Contributor Information

Subject Details
Author MiguelBc
Date October 27, 2025
Host Operating System Fedora Linux (KDE)
Relevant Software Versions Docker (with Docker Compose V2), PHP 8.x, Composer 2.x

1. Problem Summary

The php antonella serve command presented two critical issues that hindered a smooth experience in active development environments:

  1. Port Conflicts: Port assignments were fixed (e.g., 8080, 3306, 9002). If any of these ports were already in use by another service, the script would fail, forcing the user to manually edit the docker-compose.yaml file.
  2. Container Name Conflicts: The docker-compose.yaml file defined static container names (e.g., mysql-antonella). This generated a conflict error (container name is already in use) if containers from a previous session existed, preventing multiple instances of the framework from running concurrently.

2. Description of the Implemented Solution

This commit introduces a comprehensive solution addressing both problems, significantly enhancing the robustness of the development environment.

2.1. Intelligent Port Scanning Implementation

The serve command (within the antonella CLI file) has been modified to include a port detection algorithm.

  • Logic: Before executing Docker, the script now checks the availability of the required port triad (WordPress, MySQL, phpMyAdmin).
  • Iteration: If it detects that any port in the set (e.g., 8080, 3306, 9002) is occupied, it automatically increments all ports (to 8081, 3307, 9003) and checks again.
  • Execution: This process repeats until a free set of ports is found, which is then injected into Docker via environment variables.

2.2. Adoption of Dynamic Container Naming

All container_name declarations have been removed from the docker-compose.yaml file.

  • Impact: Without fixed names, Docker Compose now automatically generates unique names for each container (based on the project directory name).
  • Benefit: This completely eliminates name conflicts and allows multiple Antonella projects to run concurrently on the same host machine.

3. Modified Files

  • docker-compose.yaml: Removed 4 container_name declarations and updated the ports definitions to accept environment variables (e.g., ${WORDPRESS_PORT:-8080}).
  • antonella: Added the isPortInUse() method and expanded the logic within the serveDevelopment() method to include the port scanning algorithm.

4. Outcome and Benefits

This implementation results in a much more resilient php antonella serve command:

  • Automatic Conflict Resolution: The system now autonomously handles port and container conflicts without manual intervention.
  • Multi-Instance Support: Multiple Antonella environments can now coexist and run simultaneously on the same host machine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant