gpt4 book ai didi

Docker 和网络核心应用程序不起作用

转载 作者:行者123 更新时间:2023-12-01 07:52:04 24 4
gpt4 key购买 nike

我尝试使用 Docker 设置 dotnet 应用程序。

“后端”文件夹中的 Dockerfile:

FROM microsoft/dotnet:1.1-sdk AS build-env
WORKDIR /app
COPY *.csproj ./
RUN dotnet restore
COPY . ./
RUN dotnet publish -c Release -o out

FROM microsoft/dotnet:1.1-runtime
WORKDIR /app
COPY --from=build-env /app/out ./
CMD ["dotnet", "backend.dll"]

“前端”文件夹中的 Dockerfile:
# build
FROM node AS build-env
WORKDIR /usr/src/app

COPY package.json /usr/src/app/
RUN npm install

COPY . /usr/src/app/
RUN npm run build

# run
FROM nginx

COPY --from=build-env /usr/src/app/build /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf

nginx.conf
events {}

http {
server {
listen 80;

location / {
root /usr/share/nginx/html;
include /etc/nginx/mime.types;
}

location /api {
rewrite ^/api/?(.*) /$1 break;
proxy_pass http://api:5000;
}
}
}

docker-compose.yml
version: "3"

services:
# redis:
# image: redis
# container_name: demoapp-redis
# db:
# image: postgres
# container_name: demoapp-database
api:
build:
context: ./backend
container_name: demoapp-backend
ports:
- 5000:5000
# depends_on:
# - db
web:
build:
context: ./frontend
container_name: demoapp-frontend
ports:
- 80:80
depends_on:
- api

当我使用 dotnet run 启动我的应用程序时一切正常
MacBook-Pro-Pavel:~ pavel$ curl http://localhost:5000/values
["value1","value2"]

但是当我运行 docker-compose up我收到这条消息:
demoapp-backend | warn: Microsoft.AspNetCore.Server.Kestrel[0]
demoapp-backend | Unable to bind to http://localhost:5000 on the IPv6 loopback interface: (Error -99 EADDRNOTAVAIL address not available)
demoapp-backend | Hosting environment: Production
demoapp-backend | Content root path: /app
demoapp-backend | Now listening on: http://localhost:5000
demoapp-backend | Application started. Press Ctrl+C to shut down.

当我尝试提出请求时:
MacBook-Pro-Pavel:~ pavel$ curl http://localhost:5000/values
curl: (52) Empty reply from server
MacBook-Pro-Pavel:~ pavel$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2ae78ca79f56 demo_web "nginx -g 'daemon ..." 39 minutes ago Up About a minute 0.0.0.0:80->80/tcp demoapp-frontend
9220206e46fe demo_api "dotnet backend.dll" 7 hours ago Up About a minute 0.0.0.0:5000->5000/tcp demoapp-backend

最佳答案

我加.UseUrls("http://0.0.0.0:5000")到我的 程序.cs , 谢谢 Andy Shinn

关于Docker 和网络核心应用程序不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45065223/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com