A good option is to give a range of ports, not a specific port in docker-compose ...
ports:
- 8081+:8081
Thus, this will allow you to scale your service without going into the problem you mentioned (the port is already allocated ), as the host port will be different for each scalable instance, and Docker will handle this ...
source
share