无法使用docker-compose从容器访问ASP.net Core 2.1应用程序

时间:2019-05-09 15:14:13

标签: docker asp.net-core docker-compose

我构建了一个docker镜像并能够运行它,但是我无法使用docker-compose来实现

我有一个示例asp.net core 2.1应用程序。我可以使用Kestrel服务器在本地运行。

我使用发布的应用程序版本创建了一个docker映像,并由此创建了容器。这是我的码头工人代码

Dockerfile

FROM microsoft/dotnet:2.1-aspnetcore-runtime AS runtime
WORKDIR /app
COPY ./published/. ./
EXPOSE 80
EXPOSE 443
ENTRYPOINT ["dotnet", "Hello1.dll"]

建立图片的命令

docker build -t hello1

创建容器的命令

docker run --rm -it -p 8000:80 -p 8001:443 -e ASPNETCORE_URLS =“ https:// +; http:// +” -e ASPNETCORE_HTTPS_PORT = 8001 -e ASPNETCORE_Kestrel__Certificates__Default__Password = XXXXXXXX -e ASPNETCORE_Kestrel__Certificates__Default__Path = / root / .dotnet / https / local.pfx -v C:\ Users \ 220487.aspnet \ https:/root/.dotnet/https/ --name hello1_sample hello1

我可以访问我的应用程序https://localhost:8001/

但是,当我使用docker-compose尝试相同操作时,我无法访问https://localhost:8001/

这是我的docker-compose.yml

version: '3.6'

services:
  hello1:
    image: hello1
    ports:
      - 8001:443
      - 8000:80
    environment:
      - ASPNETCORE_URLS:"https://+;http://+"
      - ASPNETCORE_HTTPS_PORT:8001
      - ASPNETCORE_Kestrel__Certificates__Default__Password:XXXXXXXX 
      - ASPNETCORE_Kestrel__Certificates__Default__Path:/root/.dotnet/https/local.pfx
    volumes:
      - //C/Users/220487/.aspnet/https/:/root/.aspnet/https/      
    build:
      context: .
      dockerfile: Dockerfile

这是docker-compose up命令的输出

PS D:\_PROJ> docker-compose  -f "docker-compose.yml" up
Starting sample-2019-04-12_hello1_1 ... done
Attaching to sample-2019-04-12_hello1_1
hello1_1  | Hosting environment: Production
hello1_1  | Content root path: /app
hello1_1  | Now listening on: http://[::]:80
hello1_1  | Application started. Press Ctrl+C to shut down.

0 个答案:

没有答案