我使用VS为.net核心应用程序接口创建了解决方案,并启用了对Linux容器的Docker支持,也启用了对OpenAPI的支持。我甚至还有其他支持docker-compose的版本。
这两个版本,我能够在Visual studio中运行容器,浏览器立即弹出一切正常。
问题是我需要压缩并发送它,人们必须能够在没有VS的情况下运行它,只需通过命令行运行一个容器……
以下是未使用docker-compose生成的文件:
Dockerfile:
FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build
WORKDIR /src
COPY ["PhoneNumberAggregator/PhoneNumberAggregator.csproj", "PhoneNumberAggregator/"]
RUN dotnet restore "PhoneNumberAggregator/PhoneNumberAggregator.csproj"
COPY . .
WORKDIR "/src/PhoneNumberAggregator"
RUN dotnet build "PhoneNumberAggregator.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "PhoneNumberAggregator.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "PhoneNumberAggregator.dll"]launchSettings.json:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:60906",
"sslPort": 44316
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"PhoneNumberAggregator": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": "true",
"applicationUrl": "https://localhost:5001;http://localhost:5000"
},
"Docker": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
"publishAllPorts": true,
"useSSL": true
}
}
}这是使用docker-compose生成的文件(与上述内容一起计算):
这在VS中可用:
docker-compose.yml(在这个文件中,当它在localhost:8080中启动时,我添加了ports:-8080:443 ):
version: '3.4'
services:
phonenumberaggregator:
image: ${DOCKER_REGISTRY-}phonenumberaggregator
build:
context: .
dockerfile: PhoneNumberAggregator/Dockerfile
ports:
- "8080:443"和.dockerignore:
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md仍然在docker-composer版本中,但在VS中不可用,我有以下文件:
在解决方案文件夹中:
docker-compose.dcproj:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" Sdk="Microsoft.Docker.Sdk">
<PropertyGroup Label="Globals">
<ProjectVersion>2.1</ProjectVersion>
<DockerTargetOS>Linux</DockerTargetOS>
<ProjectGuid>39323510-da14-4594-918a-c8300beaa110</ProjectGuid>
<DockerLaunchAction>LaunchBrowser</DockerLaunchAction>
<DockerServiceUrl>{Scheme}://localhost:{ServicePort}/swagger</DockerServiceUrl>
<DockerServiceName>phonenumberaggregator</DockerServiceName>
</PropertyGroup>
<ItemGroup>
<None Include="docker-compose.override.yml">
<DependentUpon>docker-compose.yml</DependentUpon>
</None>
<None Include="docker-compose.yml" />
<None Include=".dockerignore" />
</ItemGroup>
</Project>和docker-compose.override.yml:
version: '3.4'
services:
phonenumberaggregator:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+:443;http://+:80
ports:
- "80"
- "443"
volumes:
- ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
- ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro在这两个版本中,我在项目中都有这个文件:
PhoneNumberAggregator.csproj.user:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ActiveDebugProfile>Docker</ActiveDebugProfile>
<Controller_SelectedScaffolderID> ApiControllerWithActionsScaffolder</Controller_SelectedScaffolderID>
<Controller_SelectedScaffolderCategoryPath> root/Common/Api</Controller_SelectedScaffolderCategoryPath>
</PropertyGroup>
</Project>顺便说一句,在VS中,当它运行时,我看到了这个端口
对于Docker版本:

对于docker-compose版本:

发布于 2021-03-13 18:47:31
看起来端口8080被映射到端口443
端口433是https,因此请确保您使用的是https://localhost:8080或https://127.0.0.1:8080
https://stackoverflow.com/questions/66612339
复制相似问题