GaryT
GaryT

Reputation: 135

In Docker for windows, how do i access a webapi running on my dev machine from the container i aslo have on my machine?

I am currently running docker for windows with a container using the asp.net core 2.0 image.

I also have a web api application running on iis on the development machine (the same machine i have docker installed with the container)

I need to be able to make an API request to the api on my dev machine.

I cant seem to get this to work.

Any help would be appreciated

Update:

My docker file

FROM microsoft/aspnetcore:2.0 AS base
WORKDIR /app
EXPOSE 80

FROM microsoft/aspnetcore-build:2.0 AS build
WORKDIR /src
COPY mysol.sln ./
COPY mysol.Web/mysol.Web.csproj mysol.Web/
RUN dotnet restore -nowarn:msb3202,nu1503

COPY . .
WORKDIR /src/CraOrchestrator.Web
RUN dotnet build -c Release -o /app

FROM build AS publish
RUN dotnet publish -c Release -o /app

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

I am running the container with

docker run -dit -p 1253:80 -v c:/data:/data --name sol mysol:latest

Upvotes: 0

Views: 1066

Answers (1)

simone.tino
simone.tino

Reputation: 2464

There should not be any problem for your containerised app to reach an app running on the host or even a different container. The problem may be in the .dockerfile.

You only need the executables in your image to correctly run your application. Your .dockerfile may look like:

# use microsoft dotnet core as base image - including ASP.NET Core
FROM microsoft/dotnet:2.0.5-runtime

# set the working directory
WORKDIR /app

# copy executables
ADD . /app

# make port 5050 available - should not matter much since this is a client app
EXPOSE 5050

# run app
CMD ["dotnet", "mysol.Web.dll"]

To create the image:

docker build -t app-image .

To run the container (and so your application):

docker run --name myapp -p 4000:5050 app-image

You may not require the port setup since the application you run is the one performing requests to the Web API running in IIS.

Upvotes: 1

Related Questions