1

I've spent hours googling this but I can't seem to find the correct pathway/documentation to help me get on the right path :(

The premise is simple.

I have a springboot application that opens on localhost:8080. I have a rabbitmq server that opens on localhost:15672

The springboot application will send messages to the rabbitmq server through some user interaction when both are running. The issue arises when I dockerize(containerize?) both these separate services Now when they are both containerized - I can still access both applications using localhost:8080 and localhost:15672, respectively. But I keep getting a "connection refused" error when my spring boot application submits the user message.

Things I have done to no avail(failure) :

  1. Both containers, when created, were using the default "bridge" network - didn't work.
  2. Tried creating my own user defined network, put both containers inside custom network - didn't work
  3. Created a docker-compose file
version: "3.2"
services:
  rabbitmq:
    image: rabbitmq:management
    ports:
      - "5672:5672"
      - "15672:15672"
    networks:
      - hin-net
app-container:
    image: spring/spring-boot-docker:latest
    ports:
      - 8080:8080
    environment:
      - SPRING_RABBITMQ_HOST=rabbitmq
    depends_on:
      - rabbitmq
networks:
  hin-net:
    driver: bridge

The only thing this did was create two docker containers automatically instead of me creating them through "docker run" - This also did not work.

Can anyone help link or provide me some guidance on how I can get my springboot application to see and connect to my rabbitMQ server? Everywhere I looked people said "make sure they're in the same docker network" but that didn't work. I suspect my docker compose file is lacking some important configuration but I'm lost on where I can go for next steps.

These two threads are pretty much my question

  1. Connect to RabbitMQ in docker-container from another container
  2. Connect java application in docker container to rabbitmq

but they're dead and a resolution was never found.

  • In that Compose setup, try deleting all of the `networks:` blocks, and configuring `SPRING_RABBITMQ_HOST=rabbitmq` as you have it (should match the Compose `rabbitmq` service name). See also [Networking in Compose](https://docs.docker.com/compose/networking/) in the Docker documentation. – David Maze Jul 12 '21 at 18:20
  • (Unrelated to the network setup, for RabbitMQ specifically, you probably need to set `hostname: rabbitmq` or something similar, or else it will forget its state on restart. The default hostname(8) is the container ID, but RabbitMQ expects it to be constant across restarts.) – David Maze Jul 12 '21 at 18:21
  • Thanks @DavidMaze I'll peruse the documentation you linked and see if it holds the nugget of truth I'm looking for – RtxTrillihin Jul 12 '21 at 18:58

1 Answers1

1

Welp found the answer. Hopefully anyone in the future who has the same question comes across this post and is able to move on with their project!

It was not a docker issue, explicitly.. The hostname of your application needs to be the containername that is running rabbitmq. So in your application.properties file in springboot, you probably set the hostname as "localhost" change it to your container name and rabbit will make the connection.

I read that this is a rabbitmq dependency. Weak, so weak.

Hope this helps anyone

Second Reference: Rabbitmq connection refused from Docker container to local host (The second answer is the right one)