简体   繁体   English

ECS 任务正在运行,但我无法在 EC2 中访问

[英]ECS Task running, but I can't access in EC2

My task's status is RUNNING and I can see the image on EC2 instance with docker ps .我的任务状态是 RUNNING ,我可以看到 EC2 实例上的图像docker ps But when I try to access the public IP and port the browser says that nothing was found.但是当我尝试访问公共 IP 和端口时,浏览器说没有找到任何东西。 I've alredy set a security group rule to allow access to all TCP ports.我已经设置了安全组规则以允许访问所有 TCP 端口。 What else can I do?我还可以做些什么?

Dockerfile: Dockerfile:

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

ENV PERSONAPI_ConnectionStrings__Database="[db connection string]"

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

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

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

Task ports:任务端口:

任务端口

Docker on EC2 instance EC2 实例上的 Docker

CONTAINER ID        IMAGE                                   COMMAND                  CREATED             STATUS              PORTS                                            NAMES
8277d3be6a74        public.ecr.aws/z0o4m5x8/padrao:latest   "dotnet personApi.dll"   2 minutes ago       Up 2 minutes        0.0.0.0:32769->80/tcp, 0.0.0.0:32768->5000/tcp   ecs-api-contato-2-api-contato-aeeefe81b1c8e7b75700

I finally figured out what was wrong.我终于弄清楚出了什么问题。 After some research I discovered that by default swagger only works in development mode, that's why I accessed when executed from Visual Studio but I couldn't access after publish.经过一些研究,我发现默认情况下 swagger 仅在开发模式下有效,这就是为什么我在 Visual Studio 中执行时访问但发布后无法访问的原因。

So I changed this configuration and published again.所以我更改了这个配置并重新发布。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM