RabbitMQ Docker Compose None of the specified endpoints were reachable - c#

I know this looks duplicated, but I checked all the others questions and none of them solved my problem.
So, this is my docker-compose yml file:
version: '3.8'
services:
#db:
# image: postgres
messageBroker:
image: rabbitmq:management
hostname: "messageBroker"
healthcheck:
test: rabbitmq-diagnostics -q ping
interval: 5s
timeout: 15s
retries: 3
networks:
- services-network
ports:
- "15672:15672"
- "5672:5672"
environment:
RABBITMQ_DEFAULT_USER: "admin"
RABBITMQ_DEFAULT_PASS: "password"
serviceDiscovery:
image: steeltoeoss/eureka-server
hostname: eureka-server
networks:
- services-network
ports:
- "8761:8761"
order-api:
image: ${DOCKER_REGISTRY-}orderapi
hostname: orderapi
environment:
- Eureka__Client__ServiceUrl=http://serviceDiscovery:8761/eureka/
- Eureka__Client__ShouldRegisterWithEureka=true
- Eureka__Client__ValidateCertificates=false
networks:
- services-network
depends_on:
- serviceDiscovery
build:
context: .
dockerfile: Services/Order/Dockerfile
links:
- "serviceDiscovery"
product-api:
image: ${DOCKER_REGISTRY-}productapi
hostname: productapi
restart: on-failure
environment:
- Eureka__Client__ServiceUrl=http://serviceDiscovery:8761/eureka/
- Eureka__Client__ShouldRegisterWithEureka=true
- Eureka__Client__ValidateCertificates=false
networks:
- services-network
depends_on:
messageBroker:
condition: service_healthy
serviceDiscovery:
condition: service_started
build:
context: .
dockerfile: Services/Products/Dockerfile
links:
- "serviceDiscovery"
- "messageBroker"
networks:
services-network:
this is my config file which I connect to RabbitMq:
using RabbitMQ.Client;
namespace MessageBroker;
public static class MessageBrokerConfig
{
public static IModel ChannelConfig()
{
var channel = new ConnectionFactory { Uri = new Uri("amqp://admin:password#messageBroker:5672") }
.CreateConnection()
.CreateModel();
return channel;
}
}
but when I run docker-compose up I still got the error:
product-api_1 | Unhandled exception. RabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the specified endpoints were reachable
product-api_1 | ---> System.AggregateException: One or more errors occurred. (Connection failed)
product-api_1 | ---> RabbitMQ.Client.Exceptions.ConnectFailureException: Connection failed
product-api_1 | ---> System.Net.Sockets.SocketException (111): Connection refused
And the product service can register inside the Service Discovery without a problem, and I followed almost the same steps.
And I know that the problem isn't the rabbitmq container taking time to be ready, because I can connect on my machine. And everytime the product service failed to launch, it restarts, but no matter how much time it takes, I still got this error. And the log of the messageBroker container shows it's healthy (and if wasn't, I would not be able to access through my machine ).
I don't have any other ideas, I'm on this problem 3 days alredy and I'm going crazy. I checked tutorials, followed the steps and nothig.

Solved, guys! Well, the configuration was correct. However, whenever I created a new container, it didn't build. Therefore, even if I changed the code, it still had the image of the first version of the code, with the "localhost" as the hostname. So the only thing I did was delete the image of the service and Docker created a new one with the correct code.
I see this obviously as a temporary solution, since it has to build everytime it runs/a new container is created. But this is another subject and I think it won't be hard to implement. Maybe with the arg --build in docker compose is enough. But I will only give attention to this later.

Your docker-compose file does not have the networking setup correctly. IMO you don't need the links. Here is a minimal docker-compose that worked for me. I removed the links and I removed the service discovery which isn't in play here for connectivity between rabbitClient and the broker.
version: '3.8'
services:
#db:
# image: postgres
messageBroker:
image: rabbitmq:management
hostname: "messageBroker"
healthcheck:
test: rabbitmq-diagnostics -q ping
interval: 5s
timeout: 15s
retries: 3
networks:
- services-network
ports:
- "15672:15672"
- "5672:5672"
environment:
RABBITMQ_DEFAULT_USER: "admin"
RABBITMQ_DEFAULT_PASS: "password"
product-api:
image: ${DOCKER-REGISTRY-}productapi
hostname: productapi
restart: on-failure
environment:
- Eureka__Client__ServiceUrl=http://serviceDiscovery:8761/eureka/
- Eureka__Client__ShouldRegisterWithEureka=true
- Eureka__Client__ValidateCertificates=false
networks:
- services-network
depends_on:
messageBroker:
condition: service_healthy
build:
context: client
dockerfile: Dockerfile
networks:
services-network:

On the docker-compose, in the network is missing something, put it like this:
networks:
services-network:
driver: bridge

Related

Postgres with .Net application in docker compose get an error: : role "root" does not exist

I have vps server on Ubuntu 20.04.
Please help me with this, i'm stuck with it, i'm starting my application with postgresql db with docker compose and get this error, what i'm doing wrong?
error screenshot
My docker-compose.yml
version: '3.8'
x-restart-policy: &restart_policy
restart: unless-stopped
services:
discord-bot:
<< : *restart_policy
depends_on:
- "postgres"
container_name: discord-bot
build:
context: .
dockerfile: DiscordBot.Application/Dockerfile
environment:
- ENVIRONMENT=Release
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
postgres:
<< : *restart_policy
image: postgres:latest
container_name: discordBot-db
env_file: .env
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
interval: 10s
timeout: 5s
retries: 5
command: ["-c", "shared_buffers=512MB", "-c", "max_connections=500"]
expose:
- '5432'
ports:
- '5432:5432'
volumes:
- ./dockervolumes/postgress/srv/postgresql/data:/var/lib/postgresql/data
My env file:
POSTGRES_HOST_AUTH_METHOD=trust
POSTGRES_DB=My_dbname
POSTGRES_USER=postgres
POSRGRES_PASSWORD=my_pass
What i'm doing wrong?
postgres:
<< : *restart_policy
image: postgres:latest
container_name: discordBot-db
user: postgres <-- Added this to service !!!
env_file: .env
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
interval: 10s
timeout: 5s
retries: 5
command: ["-c", "shared_buffers=512MB", "-c", "max_connections=500"]
expose:
- '5432'
ports:
- '5432:5432'
volumes:
- ./dockervolumes/postgress/srv/postgresql/data:/var/lib/postgresql/data
And run docker-compose up -d (to running in background)
After this I've connected to db:
docker exec -it postgres psql -U skaarl(which indicated in .env file) SkaarlDb(which indicated in .env file)
after I created postgres user and altered it as super user, after I've done docker-compose down and docker-compose up
And it works!

Docker Compose with RabbitMQ - Connection Refused when connecting from other service internally

I am using docker compose with a .net core service and RabbitMQ. I try to connect to rabbitMQ from a different service. I've seen many questions but none of them worked or had an answer.
I know you should not use 'localhost' to connect with another service but the name you gave in the docker-compose file.
I am really curious about the answer!
What I tried
Add depends on in the docker compose file
Add links in the docker compose file
Add restart: always in the docker compose file
Changed the connection link to : amqp://guest:guest#rabbitmq:5672
Changed the connection link to : amqp://guest:guest#rabbitmq/
Cleaned and rebuilt the solution many times
Changed the order in the docker compose file. RabbitMQ is now Nr.1, after that the other services.
Added container_name
Added hostname
Here is my docker compose file
version: '3.0'
services:
rabbitmq:
container_name: rabbitmq
hostname: rabbitmq
image: rabbitmq:3-management
ports:
- "7100:15672"
- "7101:5672"
volumes:
- rabbitmq:/rabbitmq
dbPosts:
image: mysql:latest
ports:
- 3307:3306
environment:
MYSQL_ROOT_PASSWORD: rootpassword
MYSQL_DATABASE: postsdb
volumes:
- dbpostdata:/var/lib/mysql
post-service:
depends_on:
- dbPosts
- rabbitmq
build:
context: .
dockerfile: post-service/Dockerfile
ports:
- "8081:80"
volumes:
dbpostdata:
rabbitmq:
How the connection is made :
if (_connection == null)
{
ConnectionFactory factory = new ConnectionFactory()
{
Uri = new Uri("amqp://guest:guest#rabbitmq:5672"),
AutomaticRecoveryEnabled = true
};
_connection = factory.CreateConnection();
}
But when I try to run docker-compose up, I receive the following error message:
Unhandled Exception: RabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the specified endpoints were reachable ---> RabbitMQ.Client.Exceptions.ConnectFailureException: Connection failed ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException: No such device or address
I fixed the issue. I got the wrong package version...

Dapr Client Docker Compose Issue

I have 3 services that I am attempting to integrate with Dapr within my local Docker instance. Each of the services is running in an Linux container.
version: '3.4'
networks:
NextWare:
external: true
services:
nextware.daprtest.service1.api:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- DAPR_GRPC_PORT=40001
ports:
- "40001:40001" # Dapr instances communicate over gRPC so we need to expose the gRPC port
- "4001:80"
depends_on:
- redis
- placement
networks:
- NextWare
volumes:
- ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
nextware.daprtest.service1.api-dapr:
image: "daprio/daprd:edge"
command: [
"./daprd",
"-app-id", "nextware.daprtest.service1.api",
"-app-port", "3001",
"-dapr-grpc-port", "40001",
"-metrics-port", "9091",
"-placement-host-address", "placement:50006", # Dapr's placement service can be reach via the docker DNS entry
"-components-path", "/components"]
volumes:
- "./components/nextware.daprtest.service1.api:/components" # Mount our components folder for the runtime to use
depends_on:
- nextware.daprtest.service1.api
network_mode: "service:nextware.daprtest.service1.api" # Attach the nodeapp-dapr service to the nodeapp network namespace
nextware.daprtest.service2.api:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- DAPR_GRPC_PORT=40003
ports:
- "40003:40003" # Dapr instances communicate over gRPC so we need to expose the gRPC port
- "4003:80"
depends_on:
- redis
- placement
networks:
- NextWare
volumes:
- ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
nextware.daprtest.service2.api-dapr:
image: "daprio/daprd:edge"
command: [
"./daprd",
"-app-id", "nextware.daprtest.service2.api",
"-app-port", "3003",
"-dapr-grpc-port", "40003",
"-metrics-port", "9093",
"-placement-host-address", "placement:50006" # Dapr's placement service can be reach via the docker DNS entry
]
volumes:
- "./components/nextware.daprtest.service2.api:/components" # Mount our components folder for the runtime to use
depends_on:
- nextware.daprtest.service2.api
network_mode: "service:nextware.daprtest.service2.api" # Attach the nodeapp-dapr service to the nodeapp network namespace
nextware.daprtest.service3.api:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- DAPR_GRPC_PORT=40005
ports:
- "40005:40005" # Dapr instances communicate over gRPC so we need to expose the gRPC port
- "4005:80"
depends_on:
- redis
- placement
networks:
- NextWare
volumes:
- ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
nextware.daprtest.service3.api-dapr:
image: "daprio/daprd:edge"
command: [
"./daprd",
"-app-id", "nextware.daprtest.service3.api",
"-app-port", "3005",
"-dapr-grpc-port", "40005",
"-metrics-port", "9095",
"-placement-host-address", "placement:50006" # Dapr's placement service can be reach via the docker DNS entry
]
volumes:
- "./components/nextware.daprtest.service3.api:/components" # Mount our components folder for the runtime to use
depends_on:
- nextware.daprtest.service3.api
network_mode: "service:nextware.daprtest.service3.api" # Attach the nodeapp-dapr service to the nodeapp network namespace
Running Docker PS I see the following containers ..
After the services are up and running I attempt to invoke the following code from Service3 to Service1 ...
var request = _mapper.Map<UpdateRequest>(integrationCommand);
await _daprClient.InvokeMethodAsync("nextware.daprtest.service1.api", "Update", request, cancellationToken);
I am getting the following exception...
Is the RequestUri correct ...
"http://127.0.0.1:3500/v1.0/invoke/nextware.daprtest.service1.api/method/Update"
Given this is the DaprClient which is invoking the sidecar, I assume the above RequestUri is correct.
What am I missing?
The reason for the error was due to a malformed ID and method name.
I moved to Tye from Docker compose and hit the same issue.
Then I altered the invocation as per this screen shot.
While this still did not call through to the Update method, it no longer returns the 500 exception.
Instead I was getting the following exception which I am just as stumped to resolve...
The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch, RemoteCertificateChainErrors
This was due to the following startup configuration setting which I commented out and all worked fine after that ...
Dapr Rocks!

Docker returning response only for http port

Here is the part of the docker compose
ecommerce.supplier:
container_name: supplier
image: ${DOCKER_REGISTRY-}ecommercesupplier
build:
context: .
dockerfile: ECommerce.Supplier/Dockerfile
ports:
- "5000:80"
- "5001:443"
env_file: ECommerce.Common/Common.env
environment:
- ConnectionStrings__DefaultConnection=Server=host.docker.internal\MSSQLSERVER01;Database=ECommerceSupplier;User Id=sa;Password=123456;MultipleActiveResultSets=true
restart: on-failure
volumes:
- ./.aspnet/supplier/DataProtection-Keys:/root/.aspnet/DataProtection-Keys
networks:
- ecommerce-network
Here is part of the Docker file for this service which exposes the ports. The file is auto generated by visual studio.
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
Here is docker ps:
So what is the result of all of this. When I hit http://localhost:5000/api/V1/Supplier/getlist with get request with proper token I receive a response. But if I try with same end point with https://localhost:5001 I receive "Could not get any response" in postman.
How I can make it work on https://localhost:5001. My level in dev ops is beginner, so if you want additional information please consider to explain carefully what exactly you need.
Side note this is happening for the all services in the screenshot.
It looks like the problem is that, inside your docker container, the application is not listening on 443.
Maybe these two links may help you:
https://learn.microsoft.com/aspnet/core/security/docker-https?view=aspnetcore-3.1
https://learn.microsoft.com/aspnet/core/security/docker-compose-https?view=aspnetcore-3.1
I would give a look at this part:
version: '3.4'
services:
webapp:
image: mcr.microsoft.com/dotnet/core/samples:aspnetapp
ports:
- 80
- 443
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+:443;http://+:80
- ASPNETCORE_Kestrel__Certificates__Default__Password=password
- ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx
volumes:
- ~/.aspnet/https:/https:ro
at the environment.ASPNETCORE_URLS property.
Hope this is helpful.

Running RabbitMQ in docker container

I am quite new when it comes to RabbitMQ and I am working on a POC to run a C# solution that's using RabbitMQ in a docker container.
I managed to write the docker-compose.yml, dockerfile and run RabbitMQ. However, my solution cannot reach the RabbitMQ host. I think I might be missing some configuration but I cannnot tell what.
docker-compose.yml
version: '3.4'
services:
rabbit-sender:
image: rabbit-sender
container_name: rabbit-sender
build:
context: ../SenderRabitMQ
dockerfile: debug.Dockerfile
env_file: common.env
networks:
- rabbitPoc
expose:
- "80"
rabbit-receiver:
image: rabbit-receiver
container_name: rabbit-receiver
build:
context: ../ReceiveRabitMQ
dockerfile: debug.Dockerfile
env_file: common.env
networks:
- rabbitPoc
expose:
- "80"
rabbitmq:
image: rabbitmq:3.7.15
hostname: rabbitmq
build:
context: rabbit
dockerfile: debug.Dockerfile
ports:
- "5672:5672"
- "15672:15672"
volumes:
- "./enabled_plugins:/etc/rabbitmq/enabled_plugins"
debug.Dockerfile
Install RabbitMQ
FROM ubuntu:14.04.1
CMD docker pull dockerfile/rabbitmq
CMD docker build -t="dockerfile/rabbitmq" github.com/dockerfile/rabbitmq
FROM dotnet-core-sdk-2.1-debug:latest AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY SenderRabitMQ/SenderRabitMQ.csproj SenderRabitMQ/
RUN dotnet restore SenderRabitMQ/SenderRabitMQ.csproj
# Copy everything else and build
COPY ./ ./
RUN dotnet publish SenderRabitMQ/SenderRabitMQ.csproj -c Debug -o out --no-restore
# Build runtime image
FROM dotnet-core-aspnet-2.1-debug:latest
WORKDIR /app
COPY --from=build-env /app/SenderRabitMQ/out .
ENTRYPOINT ["dotnet", "SenderRabitMQ.dll"]
RUN command
docker run --hostname myrabbit rabbitmq:3
Connecting to RabbitMQ
var factory = new ConnectionFactory() { HostName = "myrabbit:5672" , DispatchConsumersAsync = true };
This is the error received when running the RabbitSender that's supposed to post a message to the queue.
rabbit-sender | Unhandled Exception:
RabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the
specified endpoints were reachable ---> System.AggregateException:
One or more errors occurred. (Connection failed) --->
RabbitMQ.Client.Exceptions.ConnectFailureException: Connection
failed --->
System.Net.Internals.SocketExceptionFactory+ExtendedSocketException:
Connection refused 127.0.0.1:5672
Your docker compose sets the RabbitMQ service host name to be rabbitmq and not myrabbit (which is what you're trying to connect to). Try this instead:
var factory = new ConnectionFactory() { HostName = "rabbitmq", port = 5672 , DispatchConsumersAsync = true };
You also will need the Dockerfile rabbitmq section to be on the same network as the other services:
rabbitmq:
image: rabbitmq:3.7.15
hostname: rabbitmq
build:
context: rabbit
dockerfile: debug.Dockerfile
ports:
- "5672:5672"
- "15672:15672"
networks:
- rabbitPoc
volumes:
- "./enabled_plugins:/etc/rabbitmq/enabled_plugins"
Hope that helps!
You should use
HostName = "http://host.docker.internal:5672"
or
HostName = "host.docker.internal:5672"
instead of
HostName = "myrabbit:5672"
The reason is:
The host has a changing IP address (or none if you have no network
access). From 18.03 onwards our recommendation is to connect to the
special DNS name host.docker.internal, which resolves to the internal
IP address used by the host. This is for development purpose and will
not work in a production environment outside of Docker Desktop for
Windows.
https://docs.docker.com/docker-for-windows/networking/
In docker container,the place where you are making a connection to locally setup rabbitmq, you need to give the host as following
host.docker.internal
It will work.

Categories

Resources