0

I have a .NET 6 console app with docker-compose. The compose file is:

version: '3.4'

services:
  rms:
    image: ${DOCKER_REGISTRY-}rms
    build:
      context: .
      dockerfile: rms/Dockerfile
    restart: always
    environment:
      ENV1: a
      ENV2: b

And I have an API that runs on AWS like this: https://rms.xxx.com

If I request this API with HttpClient inside the console app with docker-compose, I get an error

No route to host (rms.xxx.com:443)

I have tried many things to solve the problem but none worked.

Here is the Dockerfile:

FROM mcr.microsoft.com/dotnet/runtime:6.0 AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["xxx.RMS.ApplicationRunner/xxx.RMS.ApplicationRunner.csproj", "xxx.RMS.ApplicationRunner/"]
COPY ["xxx.RMS.Library/xxx.RMS.Library.csproj", "xxx.RMS.Library/"]
COPY ["xxx.RMS.Repository/xxx.RMS.Repository.csproj", "xxx.RMS.Repository/"]
COPY ["xxx.RMS.Infrastructure/xxx.RMS.Infrastructure.csproj", "xxx.RMS.Infrastructure/"]
COPY ["xxx.RMS.Common.Core/xxx.RMS.Common.Core.csproj", "xxx.RMS.Common.Core/"]
RUN dotnet restore "xxx.RMS.ApplicationRunner/xxx.RMS.ApplicationRunner.csproj"
COPY . .
WORKDIR "/src/xxx.RMS.ApplicationRunner"
RUN dotnet build "xxx.RMS.ApplicationRunner.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "xxx.RMS.ApplicationRunner.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "xxx.RMS.ApplicationRunner.dll"]

How can I solve the problem? How to communicate between the console app with docker-compose and a random API?

Note: I couldn't insert API information to this compose file like adding another service.

Emir Kılınç
  • 543
  • 6
  • 15
  • 1
    https://stackoverflow.com/questions/45509604/docker-container-can-not-ping-the-outside-world-iptables, https://stackoverflow.com/questions/20430371/my-docker-container-has-no-internet, and so on. Debug your container, shell into it, ping/netcat/dig the outside world. – CodeCaster May 17 '23 at 12:00
  • @ServeLaurijssen no port because it is a console app? Why do I need a port for the console app? – Emir Kılınç May 17 '23 at 12:14
  • @CodeCaster There is no easy way, right? Why am I fixing the Linux host file for local purposes? Is there any option that I add to the compose file for communication between API and console app? – Emir Kılınç May 17 '23 at 12:19
  • 1
    There is an easy way. All of this should just work out of the box. I just gave you some troubleshooting links. If it doesn't work out of the box, it's probably your machine's or network's setup that's causing this. Do you have a proxy server on your network? – CodeCaster May 17 '23 at 12:22
  • 1
    I misread, you try to connect to another api. usually you do what codecaster said. the containers take their config from the distro layer so there's probably something wrong there. traceroute could help too, maybe the ip gets blocked – Serve Laurijssen May 17 '23 at 12:33
  • You two say it is a kinda network problem. So how can I solve this? How can I detect it? Where should I look for? AWS internal ELB (ElasticLoad Balancer) config maybe? – Emir Kılınç May 17 '23 at 14:31

0 Answers0