I have an ASP.Net MVC web application (.Net Framework 4.6) that I usually ran in local dev machine (let's say it's running on localhost:10000
). The application connect to few local services:
- Database
- Azure Storage (emulator)
- Azure Cosmos (emulator)
Local dev machine (the host) is running on Windows 10.
Question
I'm in the process of moving this application to a Docker container and was able to run the application off of a Docker container.
My question is, how do I configure the network in (using Docker Compose or docker run
so that the application (that's in the the container) can connect to the services (database, storage and cosmos emulator) that are in my host?
What I have tried
- Use
host.docker.internal
- Docker compose default network
- Docker compose (
network_mode: host
) - Docker CLI (
run --network
) - SQL Server to listen to all ports
None of these work. I still get error when connecting from Container to Host.
Error
Other Configurations
I'm using Dockerfile
and Docker Compose yml files to build and run the container locally.
Dockerfile
file
# escape=`
FROM mcr.microsoft.com/dotnet/framework/sdk:4.8 AS build
WORKDIR /app
# Copy everything else and build app
COPY Web/Web/. ./Web/Web/
# Build the projects
WORKDIR /app/Web/Web
RUN msbuild /p:Configuration=Debug
FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8 AS runtime
WORKDIR /inetpub/wwwroot
# Configure website
SHELL ["powershell", "-command"]
# Install ASP.NET
RUN Install-WindowsFeature Web-Asp-Net45
EXPOSE 10000
RUN Remove-Website -Name 'Default Web Site'; `
New-Website -Name 'Web' `
-Port 10000 -PhysicalPath 'c:\inetpub\wwwroot' `
-ApplicationPool '.NET v4.5'
# Final copy for build
COPY --from=build /app/Web/. ./
Docker Compose yml file.
version: '3.5'
services:
web:
build: .
ports:
- "10000:10000"