how to call api endpoint inside docker container?
Asked Answered
D

1

7

My action endpoints are usually http://localhost:50000/Method/egFunction but when I run the app on a docker container, I am not able to call the api endpoint, I get errors instead. I use docker-compose and here is my code (mongodb also doesn't work yet, I'm trying to get the endpoint working first).

I always used docker-compose up to run the app, but ever since I implemented the restful api's and a database, I might have to change the way to run the command, not sure though. If I do docker-compose up the front-end loads fine but I have no data, and every call to the endpoint gives me an error. I usually load the docker container with this link: http://192.168.99.100:8080

I have this in the docker-compose.yml:

version: '3.4'

services:
  app:
    image: vinnie_app:latest
    links:
      - mongodb
    depends_on:
      - mongodb
  mongodb:
    image: mongo:latest
    container_name: "mongodb"
    ports:
      - 27017:27017

In my docker-compose.override.yml file I have this:

version: '3.4'

services:
  app:
    build: ./app
    environment:
      - ASPNETCORE_ENVIRONMENT=Staging
      - NODE_ENV=staging
    ports:
      - "8080:80"

dockerfile:

FROM microsoft/dotnet:sdk AS build-env
WORKDIR /app

RUN curl -sL https://deb.nodesource.com/setup_10.x |  bash -
RUN apt-get install -y nodejs

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

# Build runtime image
FROM microsoft/dotnet:aspnetcore-runtime
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "app.dll"]
Delegate answered 14/11, 2018 at 16:38 Comment(6)
Well since your endpoint uses port 50000 you should probably map that. It would also be helpful if you had the error messages in your postJewess
how do you map port 50000?Delegate
The same way you mapped port 8080Pintail
The same way you mapped 8080 to 80 (why are you using port 8080 not 80?) and 27017 to 27017, just add another line below with 50000:50000. Another thing, how come you're not using localhost. What is 192.168.99.100 exactly?Jewess
I'm using docker-toolbox, so it has some issues for loading localhost . I'll try adding another line with 50000:50000 and let you know.Thank youDelegate
since my docker link is 192.168.99.100:50000 and it cant read from the localhost:50000 endpoint, my docker container cant use the restful api's!Delegate
L
0

Internally, docker routes to localhost via host.docker.internal:[portnumber]

If localhost is not routing, try that. Should work.

Languet answered 9/7 at 0:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.