I am using consul as a service dicovery in a microservice architecture. Currently the parts involved are: configuration-server, gateway, service1 and service2. When I use consul in localhost everything works correctly. The microservice ports are assigned by consul in dynamic mode. Using consul and all the microservices inside the docker on a virtual machine I have problems with the communication between the various microservices due to the insulation of the containers. In particular when the doors of the single microservices are assigned by consul. I give an example, considering the service1 , inside the docker file I expose the port 8080 for the communication of the caontainer with the outside world. The integrated server is started on a dynamic port assigned by consul 46829.
To start the container from the docker console I use the command:
docker run -P –name service1-1 service1: latest
The container is started correctly by mapping a port other than the one assigned by consul to the 8080 of the container, making sure that the service is not reachable by the others since using service dicovery the service1 is called with the port assigned by consul. If I start the service in consul with the docker run command -p 8080: 8080 –name service1-1 service1: latest everything works perfectly but I lose the functionality of the service dicoveryIs there any way to make the two doors coincide? Thanks in advance