5
Manao
6y

Okay... I am more than annoyed. 😵😵😵 I've been trying for days to get 2 small dockerized Spring REST-Services to communicate with each other. Without docker the services work fine with each other. I've tried many tutorials, examples, hints online and so on and none works or does something else. There is so much deprecated stuff or huge tutorials where I have to install 1000 other useless things. I kinda feel like this Microservice Stuff is a myth or I'm just stupid. Even my partner has no clue.

Comments
  • 1
    have you tried adding links in each service's docker-compose file?
  • 0
    @uuid
    Yes I've set links between the services using a .yml file with docker-compose...
  • 0
    I'm just getting a connection refused.
  • 1
    How about you "ssh" into them with
    docker exec --it containername bash
    And do some manual tests? Maybe checking the ip-configuration will help you, at least getting those insights always helped me.

    Btw: don't try any ip-configuration in swarm-mode, docker is shit when it comes to this.
  • 1
    @YouAreAPIRate update: the docker command only takes one hyphen:
    docker exec -it containername bash
    (If bash isn't available in the container just use sh)
  • 1
    @YouAreAPIRate Thx for your help. 😘 I still have no clue.
    I would be happy If I could find some small examples online. I'm new to this docker-stuff and have to get just 2 little Springboot Apps talking to each other with get / post. Without dockerizing all this spring stuff was easy-going. With docker it's kinda hell for me. I guess I've done something wrong with the ports. I just don't know what. 😂
  • 1
    @Manao do you have the output of docker ps and docker network inspect therestservicenetwork? Maybe it's something very simple and you just try to connect to a container on a public port number where the container-internal port number is needed.
    Oh, and don't forget to run netstat -ntl if possible to get a list of ports your container listens on. Good luck.
  • 0
    @YouAreAPIRate Yeah, here are my outputs. Don't be confused by the names of each service. Currently they are all plain springboot apps. :)
  • 0
    @YouAreAPIRate .. and my network-check:
  • 1
    @Manao that leaves only one question: what ports are your services configured to run on? That number should be in your code. E.g. if your "gui" is running on port 1234 you still hve your port redirection from port 8081 outside to 8081 "gui", which is pointless of course. But inside the network you would have to use port 1234 to connect to the container (assuming you use the container hostname as dns address)
  • 0
    @YouAreAPIRate

    In my Java-Code the services access each other with a simple url and some get or post-request. Without Docker I've started each app on their own port, so that I can access something like:

    "http://localhost:8081/addEventToDB" - this works fine.

    Now with each app dockerized I'm pretty clueless. And tried many things like send a POST to: "http://cassandradb/addEventToDB/" (as you said using the container hostname) and so on (I've named each app in a .yml file).

    Hope this information helps. :S
  • 1
    @Manao containers run as a service run in their own little network, as you've already seen. You can imagine it like a normal wifi-network with your docker host as router.
    If you want one container in the network to talk to another you need to get port and hostname right (the ip changes on redeployments so it's no use). You can check the hostnames by running cat /etc/hosts in a container (via docker exec), in there every host in the network is listed. The port should be the one you used before when you used localhost in the url. At least that's what i see from your config, every container is running his service on 808X-ports and you do a redirect on localhost for the same port.
  • 1
    @Manao e.g. the gui-container should be able to talk to the database via protocol://cassandradb:9300/ . The only thing that can go wrong here is a wrong number in your code (things happen ^^") or docker messing up the ip- and/or dns-configuration (i had my fair share of problems when using docker swarm). For further investigation i normally open up a shell in the container and install some ip-tools (e.g. the ip-command via package iproute2 or netstat via package net-utils). I don't know how good you're with linux-networking but this always is an last option.
  • 1
    @Manao oh, and i almost forgot something important. I put in in the back of my head because that feature cannot be used when you're running your docker container on more than one computer. But otherwise you can force-set the ip-address-range of your docker network and the individual ip-addresses of your docker containers. You can look that up in the documentation of docker compose files. If there is really no other option you can give the containers static ip-addresses (i recommend a ip-range of 192.168.XXX.0/24 for the network) and use those ip-addresses in your code. It's ugly but it works.
  • 1
    @YouAreAPIRate Oh.. thank you sooo much. :) I have already tried "http://cassandradb:9300" I still got a ConnectionRefused-Error.

    I will go through your points asap and will let you know, if it worked or helped me to find the root of all the evil. :)

    I really appreciate your help.
  • 1
    @Manao are these containers or the same network? Because I remember getting connection refused when I tried setting up a communication between a rest api and a db, it turned out that they weren't on the same network.
  • 0
    @uuid look at the second picture she sent, the one with the output of "docker network inspect". All her containers are in the same network, which is what happens by default if you use docker compose.
  • 1
    @YouAreAPIRate yeah true, my bad.
Add Comment