dotnet 核心 docker 网络 api 未连接
dotnet core docker web api not connecting
我正在努力让我的 docker 容器在本地主机上侦听(一直无法访问站点)。我遵循了 jetbrains 的官方指南和我在网上找到的其他一些指南,但仍然没有运气。
在我的本地开发中,我希望我的 web API 容器和 Postgres 容器相互通信,但在运行时容器将与 en RDS 实例通信
Docker文件
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS base
WORKDIR /app
EXPOSE 8080
ENV ASPNETCORE_URLS=http://+:8080
# Copy csproj and restore as distinct layers
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /src
COPY . .
RUN dotnet restore "api/api.csproj"
WORKDIR "/src/api"
RUN dotnet build "api.csproj" -c Release -o /app
FROM build AS publish
WORKDIR "/src/api"
RUN dotnet publish "api.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "api.dll", "--urls", "http://*:8080"]
启动设置
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:14317",
"sslPort": 44301
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"wander.api": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "",
"applicationUrl": "https://localhost:8081;http://localhost:8080",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
我的 Docker 调试配置
我的dockerPS
请分享您的 docker run
命令。我确定您指定了 -p
选项。
我猜它看起来像下面这样:
docker run <cotainer id> -p 57000:8080
8080 将从 docker 容器网络中使用。
从主机您可以使用 57000
.
访问 API
我正在努力让我的 docker 容器在本地主机上侦听(一直无法访问站点)。我遵循了 jetbrains 的官方指南和我在网上找到的其他一些指南,但仍然没有运气。
在我的本地开发中,我希望我的 web API 容器和 Postgres 容器相互通信,但在运行时容器将与 en RDS 实例通信
Docker文件
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS base
WORKDIR /app
EXPOSE 8080
ENV ASPNETCORE_URLS=http://+:8080
# Copy csproj and restore as distinct layers
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /src
COPY . .
RUN dotnet restore "api/api.csproj"
WORKDIR "/src/api"
RUN dotnet build "api.csproj" -c Release -o /app
FROM build AS publish
WORKDIR "/src/api"
RUN dotnet publish "api.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "api.dll", "--urls", "http://*:8080"]
启动设置
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:14317",
"sslPort": 44301
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"wander.api": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "",
"applicationUrl": "https://localhost:8081;http://localhost:8080",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
我的 Docker 调试配置
我的dockerPS
请分享您的 docker run
命令。我确定您指定了 -p
选项。
我猜它看起来像下面这样:
docker run <cotainer id> -p 57000:8080
8080 将从 docker 容器网络中使用。
从主机您可以使用 57000
.