0

I have two .NET core web APIs as docker containers. I want with NetMQ one to send messages and other listen to it. But I think I have some problems connectiong those two with tcp connection. I use Docker compose.

version: '3.4'

services:
  gateway:
    image: ${DOCKER_REGISTRY-}gateway
    build:
      context: .
      dockerfile: Gateway/Dockerfile
    ports:
        - 5000:80

  pictureperfect:
    image: ${DOCKER_REGISTRY-}pictureperfect
    build:
      context: .
      dockerfile: PicturePerfect/Dockerfile
    ports:
     - 5001:80
     - 5002:5002

I want this one to send message

      private void Send() {
         using (var requester = new RequestSocket("tcp://0.0.0.0:5002")) {
            try {
               requester.SendFrame("message from pp");
               Console.WriteLine(requester.ReceiveFrameString());
            } catch (Exception) {
               throw;
            }
         }
      }

This is the one that I want to be listening

public static void Main(string[] args) {
         CreateHostBuilder(args).Build().Run();

         using (var responder = new ResponseSocket()) {
            responder.Bind("tcp://pictureperfect:5002");
            while (true) {
               Console.WriteLine(responder.ReceiveFrameString());
               Thread.Sleep(1000);
               responder.SendFrame("message from gateway");
            }
         }
      }

jps
  • 20,041
  • 15
  • 75
  • 79
  • In a container, an address like this:`tcp://0.0.0.0:5002` will point to itself. If you want to listen to the other container you need to use its own IP address or hostname if you running this in your development environment. – Eldar Jun 17 '21 at 10:20
  • Hey Eldar! thank you so much for your response. I am still confused how this tcp ports work in docker and also in general I have knowledge gaps about tcp ports. could you advice some article or video about that? – Sidamonidze Roland Jun 17 '21 at 11:45
  • [this](https://www.simplilearn.com/tutorials/docker-tutorial/docker-networking) document may help you understanding docker networking. If we summarize what's happening as the containers are virtual machines they have their own network endpoints and ports but in a shared network when you expose ports in your compose file local ports bind to host machines ports. – Eldar Jun 17 '21 at 12:04

0 Answers0