how to call api endpoint inside docker container?

10.4k views Asked by At

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"]
0

There are 0 answers