I have a web server written in Go that interacts with Rabbitmq and Mongodb. When I run all these servers on my machine without containers (rabbitmq url: amqp://guest:guest@localhost:5672
) it works fine.
Now I am trying to run all these services in a separate container. Here is my compose file
version: '3'
services:
rabbitmq:
image: rabbitmq
container_name: rabbitmq
ports:
- 5672:5672
mongodb:
image: mongo
container_name: mongodb
ports:
- 27017:27017
web:
build: .
image: palash2504/collect
container_name: collect-server
restart: on-failure
ports:
- 3000:3000
depends_on:
- rabbitmq
- mongodb
links: ["rabbitmq", "mongodb"]
networks:
default:
external:
name: collect-net
This is my servers dockerfile
FROM golang
ENV GO111MODULE=on
WORKDIR /app
COPY go.mod .
COPY go.sum .
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build
EXPOSE 3000
ENTRYPOINT ["/app/social-cops-assignment"]
My server can't seem to connect to rabbitmq. This is the log message I get when running docker compose up
and the rabbitmq url in my config being amqp://guest:guest@rabbitmq:5672
(since the container name is rabbitmq I replace localhost with rabbitmq so that my server is able to find the rabbitmq container)
collect-server | 2019/03/10 08:50:51 Failed to connect to AMQP compatible broker at: amqp://guest:guest@rabbitmq:5672/, with errror: dial tcp 172.24.0.3:5672: connect: connection refused
But rabbitmq seems to be ready to accept connections. These are the last two lines of the rabbitmq logs from docker-compose up
rabbitmq | 2019-03-10 08:50:55.164 [info] <0.489.0> accepting AMQP connection <0.489.0> (172.24.0.4:49784 -> 172.24.0.3:5672)
rabbitmq | 2019-03-10 08:50:55.205 [info] <0.489.0> connection <0.489.0> (172.24.0.4:49784 -> 172.24.0.3:5672): user 'guest' authenticated and granted access to vhost '/'
I am new to docker-networking and I don't know what am I doing wrong? Is it the rabbitmq address that I am using or I need some additional configuration with respect to rabbitmq or expose some ports?
docker-compose restart web
and check if the issue still exist ? just make sure you don't restart rabbitmq – Marinara