首页 > 解决方案 > 如何正确编写 docker-compose 文件

问题描述

我创建了 asp.net 核心 MVC 应用程序。配置自签名证书以使用 https 连接并使用此命令在 docker 容器中运行它

docker run --rm -it -p 5000:80 -p 5001:443 -e ASPNETCORE_URLS="https://+;http://+" -e ASPNETCORE_HTTPS_PORT=5001 -e ASPNETCORE_Kestrel__Certificates__Default__Password="password" -e ASPNETCORE_Kestrel__Certificates__Default__Path=/https/identitycert.pfx -v ${HOME}/.aspnet/https:/https/ kirillbasic/identityserver

我可以轻松连接到我的本地主机。但后来我尝试使用看起来像这样的 docker-compose.yaml 文件

services:
 identityserver:
  image: kirillbasic/identityserver:test
  ports: 
   - "4999:80"
   - "5000:433"
  environment:
   ASPNETCORE_URLS: https://+;http://+
   ASPNETCORE_HTTPS_PORT: 5000
   ASPNETCORE_Kestrel__Certificates__Default__Password: password
   ASPNETCORE_Kestrel__Certificates__Default__Path: /https/identitycert.pfx
  volumes: ["${HOME}/.aspnet/https:/https/"]

我得到“安全连接失败”。我尝试了不同的打字方式:带括号和不带括号,但没有任何帮助。有没有人有任何建议为什么会发生,我该如何解决这个问题?

标签: dockerdocker-compose

解决方案


由于 3.3 docker-compose 版本文件中的正则表达式字符,您需要用单引号将该变量括起来。你能试试这个,看看它是否有效。

version: '3.3'
    services:
        identityserver:
            image: kirillbasic/identityserver
            ports:
                - '5000:80'
                - '5001:443'
            environment:
                - 'ASPNETCORE_URLS=https://+;http://+'
                - ASPNETCORE_HTTPS_PORT=5001
                - ASPNETCORE_Kestrel__Certificates__Default__Password=password
                - ASPNETCORE_Kestrel__Certificates__Default__Path=/https/identitycert.pfx
            volumes:
                - '${HOME}/.aspnet/https:/https/'
            

推荐阅读