若选择web项目支持https,此时launchSettings.json文件为:
"iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { "applicationUrl": "http://localhost:54372", "sslPort": 54373 }
此时sslPort不为0(开启https时)http和https两种协议的端口都固定Dockerfile文件中可以不暴露端口(EXPOSE可以不设置),如:
#EXPOSE 80 #EXPOSE 443
sslPort修改为0(关闭https时)每次重新编译程序端口号会递增,无法固定。Dockerfile文件中必须暴露端口,如:
EXPOSE 80
80和443两个默认端口都可以通过Dockerfile进行修改,如:
ENV ASPNETCORE_URLS http://+:81
或
ENV ASPNETCORE_URLS http://+:81,https://+:444
EXPOSE 跟着改。
另:vs+docker启动环境下,多种方式修改配置,环境变量始终为Development,代码内修改除外。
Production部分
启用https时docker-compose.override.yml文件为
aspnetcore环境变量修改为非Development时,若无证书,docker-compose启动会报错
此时内容为:
version: ‘3.4‘ services: dockerlinuxdemo.web: restart: always environment: - ASPNETCORE_ENVIRONMENT=Production - ASPNETCORE_URLS=https://+:443;http://+:80 - ASPNETCORE_HTTPS_PORT=38112 ports: - "38111:80" - "38112:443" volumes: - ./DockerLinuxDemo.Web/bin/Release/netcoreapp2.1/publish:/app - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
不启用https时修改ASPNETCORE_URLS即可,ASPNETCORE_HTTPS_PORT和ports并不影响:
version: ‘3.4‘ services: dockerlinuxdemo.web: restart: always environment: - ASPNETCORE_ENVIRONMENT=Production - ASPNETCORE_URLS=http://+:80 - ASPNETCORE_HTTPS_PORT=38112 ports: - "38111:80" - "38112:443" volumes: - ./DockerLinuxDemo.Web/bin/Release/netcoreapp2.1/publish:/app - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
docker-compose up --build -d 挺方便的
原文地址:https://www.cnblogs.com/wintersoft/p/9902734.html
时间: 2024-10-31 03:41:23