What I am trying to accomplish
The final result I'm trying to create is a scenario in which the Web API is not exposed to the localhost, yet the Web MVC website can communicate with the Web API, parsing its results.
Background
I'm new to the Docker world, and as I learned how to run multi containers side-by-side, now I'm trying to back-track everything I have learned so far using networking between two of the containers.
I have created two simple, out-of-the-box .NET 5.0 applications:
1. Web API (reaching through HTTP, using port 7070)
- Dockerfile:
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 7070
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["CreatingWebAPI/CreatingWebAPI.csproj", "CreatingWebAPI/"]
RUN dotnet restore "CreatingWebAPI/CreatingWebAPI.csproj"
COPY . .
WORKDIR "/src/CreatingWebAPI"
RUN dotnet build "CreatingWebAPI.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "CreatingWebAPI.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENV ASPNETCORE_URLS http://+:7070
ENTRYPOINT ["dotnet", "CreatingWebAPI.dll"]
launchSettings.json:
"Docker": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
"publishAllPorts": true,
"useSSL": true
}
- Also defined
Program.csCreateHostBuilder(string[] args)as follow:
webBuilder.UseUrls("http://*:7070").UseStartup<Startup>();
2. Web MVC that shows a parsed table from the Web API
The issue I'm currently facing
Running the Web API application through Visual Studio (using Docker configuration) works just fine, and I can access the localhost:<port>/swagger without an issue. The problem is that while trying to reproduce the same process using the Docker CLI - I cannot access the /swagger interface matter what or what port I'm trying to access.
Attached is a photo of the docker CLI showing the same details about both of the containers:

- Generated using Visual Studio
- Generated using
docker run --network personal-net --name api -p 50000:7070 creatingwebapi
I have used different networks and tried to create only one of them at a time. I even tried docker container inspect on both of these to check for any differences between them without seeing anything different. What might be the issue then?