简体   繁体   中英

Which port is my ASP.NET Core 6 app running on in AWS Fargate

I just did the following:

  1. Created an ASP.NET Core 6 API in Visual Studio with the docker option selected
  2. Built the docker image
  3. Uploaded the image to AWS ECR
  4. Crated a cluster, task definition and service

Now I can see my task running, but I don't know how to connect to the API. Port 80 and 443 don't do anything and neither do 7260 and 5260, which are used locally for debugging.

Below is my current config for everything (I got desperate and added all sorts of ports I was hoping might be relevant).

Dockerfile:

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
EXPOSE 7260
EXPOSE 49159
EXPOSE 5260
...

launchSettings.json in the project:

{
  "$schema": "https://json.schemastore.org/launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:57003",
      "sslPort": 44385
    }
  },
  "profiles": {
    "CoffeSubscription": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "https://localhost:7260;http://localhost:5260",
      "dotnetRunMessages": true
    },
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "Docker": {
      "commandName": "Docker",
      "launchBrowser": true,
      "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
      "publishAllPorts": true,
      "useSSL": true
    }
  }
}

Port mappings on task definition:

在此处输入图像描述

Task ENI security group settings (Allow everything from everywhere [Yes, for testing only]):

在此处输入图像描述

If anybody has any advice I'd be immensely grateful.

EDIT

I managed to set the port the app starts on by adding the following to my Dockerfile

EXPOSE 80
EXPOSE 443

ENV ASPNETCORE_URLS="http://*:80;https://*:443"

Thanks everybody your comments pointed me in the right direction.

I will suggest you to pass the following environment variable into your Fargate service, so you can manage the port your application lives on:

ASPNETCORE_URLS: http://0.0.0.0:8080

In this example will your application be exposed on port 8080

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/taskdef-envfiles.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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