Docker-compose与.NET Core无法访问 [英] Docker-compose with .NET Core unreachable

查看:65
本文介绍了Docker-compose与.NET Core无法访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Docker的新手,我试图设置2个容器,一个运行mongoDB,一个运行Web应用程序.

问题是我无法通过localhost:5000或0.0.0.0:5000访问我的.NET Core应用程序.

Mongo运行正常.

这是我的docker-compose.yml

 版本:"3"服务:网络:建造: .端口:-"5000:5000"蒙哥:构建:../../../docker/wishare-mongo/数量:-../../../docker/wishare-mongo:/data/db端口:-"27017:27017" 

用于.NET Core应用程序的Dockerfile

  FROM microsoft/aspnetcore-build:2.0 AS build-envWORKDIR/appENV ASPNETCORE_URLS ="http://*:5000"#复制csproj并还原为不同的层COPY * .csproj ./运行dotnet还原#复制其他所有内容并进行构建复制 ../RUN dotnet发布-c发布-o out#构建运行时映像从microsoft/aspnetcore:2.0WORKDIR/app复制--from = build-env/app/out.曝光5000ENTRYPOINT ["dotnet","Wishare-Integration-Api.dll"] 

docker-compose构建和docker-compose up运行没有错误,从而导致Web容器:

web_1 |托管环境:生产web_1 |内容根路径:/app web_1 |现在收听:

有什么想法吗?

解决方案

看起来.NET在生产中使用端口80,因此当Ive更改docker文件并导出端口80而不是5000时,也将端口5000更改为docker中的端口80-使其按预期工作.

因此,我认为为了在端口5000上运行它,将需要在.NET端进行一些配置.

Im new to Docker and im trying to set up 2 containers, one running mongoDB and one running the web application.

The problem is that I can not access my .NET core application via localhost:5000 or 0.0.0.0:5000.

Mongo is running fine.

Here is my docker-compose.yml

version: '3'
services:
  web:
    build: .
    ports:
     - "5000:5000"
  mongo:
    build: ../../../docker/wishare-mongo/
    volumes:
     - ../../../docker/wishare-mongo:/data/db
    ports:
     - "27017:27017"

Dockerfile for .NET Core app

FROM microsoft/aspnetcore-build:2.0 AS build-env
WORKDIR /app
ENV ASPNETCORE_URLS="http://*:5000"

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

# Build runtime image
FROM microsoft/aspnetcore:2.0
WORKDIR /app
COPY --from=build-env /app/out .
EXPOSE 5000
ENTRYPOINT ["dotnet", "Wishare-Integration-Api.dll"]

The docker-compose build and docker-compose up runs without an error with this resulting for web container:

web_1 | Hosting environment: Production web_1 | Content root path: /app web_1 | Now listening on: http://[::]:80 web_1 | Application started. Press Ctrl+C to shut down.

And this is the result of docker ps, port 5000 should be exported based on docker ps result.

Any ideas?

解决方案

Looks like .NET uses port 80 in production, so when Ive changed docker file and exported port 80 instead of 5000 and also changed port 5000 to port 80 in docker-compose it works as supposed.

So I assume in order to run it on port 5000 it will need some configuration on .NET side.

这篇关于Docker-compose与.NET Core无法访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆