gpt4 book ai didi

azure - 容器在本地运行但在 ACI 中失败

转载 作者:行者123 更新时间:2023-12-03 02:22:41 25 4
gpt4 key购买 nike

我创建了一个由 dotnet new web 生成的示例 asp.net core 应用程序。添加了暴露端口 5000 的 docker 文件。

Docker 文件如下

FROM mcr.microsoft.com/dotnet/aspnet:5.0-focal AS base
WORKDIR /app
EXPOSE 5000

ENV ASPNETCORE_URLS=http://+:5000

# Creates a non-root user with an explicit UID and adds permission to access the /app folder
# For more info, please refer to https://aka.ms/vscode-docker-dotnet-configure-containers
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
USER appuser

FROM mcr.microsoft.com/dotnet/sdk:5.0-focal AS build
WORKDIR /src
COPY ["Sampleapp.csproj", "./"]
RUN dotnet restore "Sampleapp.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "Sampleapp.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Sampleapp.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Sampleapp.dll"]

当我在桌面上本地运行它时,效果很好。但是,当我将其添加到 ACR 并在 ACI 中运行它时,它失败了。

az container create --resource-group $res_grp `
--name $aci_container_name `
--image $image_name `
--registry-login-server $registry_login_server `
--registry-username $akv_pull_usernamevalue `
--registry-password $akv_pullpasswordvalue `
--dns-name-label $dns_name_label `
--output table

Name ResourceGroup Status Image IP:ports Network CPU/Memory OsType Location
---------------- ------------------ -------- ---------------------------------------------------- ---------------- --------- --------------- -------- -------------
aci0734container containerbasics_rg Running devcontainerregistry0734.azurecr.io/helloacrworld:v1 20.53.163.177:80 Public 1.0 core/1.5 gb Linux australiaeast

也没有错误日志。

az container logs --resource-group containerbasics_rg --name aci0734container

info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://[::]:5000
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: /app

当我尝试 curl 时,这是响应

curl http://20.53.163.177:5000
curl : Unable to connect to the remote server
At line:1 char:1
+ curl http://20.53.163.177:5000
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

当我在本地运行它时,我映射目标端口,但 ACI 不允许端口映射。是这个问题吗?

最佳答案

您需要通过添加 --ports 5000 来公开非标准端口。 ACI 默认使用端口 80,您的实例正在监听并公开端口 5000:

az container create --resource-group $res_grp `
--name $aci_container_name `
--image $image_name `
--registry-login-server $registry_login_server `
--registry-username $akv_pull_usernamevalue `
--registry-password $akv_pullpasswordvalue `
--dns-name-label $dns_name_label `
--ports 5000 `
--output table

关于azure - 容器在本地运行但在 ACI 中失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68220207/

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