title: API doesn't work, using Docker and ASP.NET CORE
body: <p>I made an ASP.NET Core web API that pings a Mongodb and a docker container for it. The web api calls work when not using docker but returns a Not Found error when I do use it. I think it has something to do with the ports I'm running on but I'm not sure cause this is the first time I've used docker.</p>
  <p>In the command prompt I do:</p>
  <p><code>docker build -t projectname .</code></p>
  <p>And then I run the image with</p>
  <p><code>docker run -p 8080:80 projectname</code></p>
  <p>Once running, if I make a call to http://localhost:8080/api/classname, I get a Not Found error with the message &quot;this is my invalid message&quot; so it seems like my docker container IS running. When I make a call to http://localhost:8080/api/classname?id=1 (this is a valid id), I still get a Not Found error but don't get the &quot;this is my invalid message&quot; text.</p>
  <p>ClassNameController API GET:</p>
  <pre><code>[Route(&quot;api/[controller]&quot;)]
      [ApiController]
      public class ClassNameController : Controller
      {
          [HttpGet]
          public IActionResult GetDescendents(int id)
          {
              var mongoDbService = new MongoDbService();
  
        
              try
              {
                  var node = mongoDbService.GetTreeNodeById(id);
  
                  if (node == null)
                  {
                      return NotFound(&quot;this is my invalid message&quot;);
                  }
                  else
                  {
                      //stuff happens
                  }
              }
              catch (Exception e)
              {
                  return BadRequest(e);
              }
  
              return Ok();
          }
  </code></pre>
  <p>Dockerfile:</p>
  <pre><code>See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
  
  FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
  WORKDIR /app
  EXPOSE 80
  EXPOSE 443
  
  FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
  WORKDIR /src
  COPY [&quot;ProjectName/ProjectName.csproj&quot;, &quot;ProjectName/&quot;]
  RUN dotnet restore &quot;ProjectName/ProjectName.csproj&quot;
  COPY . .
  WORKDIR &quot;/src/ProjectName&quot;
  RUN dotnet build &quot;ProjectName.csproj&quot; -c Release -o /app/build
  
  FROM build AS publish
  RUN dotnet publish &quot;ProjectName.csproj&quot; -c Release -o /app/publish
  
  FROM base AS final
  WORKDIR /app
  COPY --from=publish /app/publish .
  ENTRYPOINT [&quot;dotnet&quot;, &quot;ProjectName.dll&quot;]
  </code></pre>
  <p>launchSetting.json:</p>
  <pre><code>{
    &quot;iisSettings&quot;: {
      &quot;windowsAuthentication&quot;: false,
      &quot;anonymousAuthentication&quot;: true,
      &quot;iisExpress&quot;: {
        &quot;applicationUrl&quot;: &quot;http://localhost:8080&quot;,
        &quot;sslPort&quot;: 8080
      }
    },
    &quot;$schema&quot;: &quot;http://json.schemastore.org/launchsettings.json&quot;,
    &quot;profiles&quot;: {
      &quot;IIS Express&quot;: {
        &quot;commandName&quot;: &quot;IISExpress&quot;,
        &quot;launchBrowser&quot;: true,
        &quot;launchUrl&quot;: &quot;&quot;,
        &quot;environmentVariables&quot;: {
          &quot;ASPNETCORE_ENVIRONMENT&quot;: &quot;Development&quot;
        }
      },
      &quot;DockerAPI&quot;: {
        &quot;commandName&quot;: &quot;Project&quot;,
        &quot;launchBrowser&quot;: true,
        &quot;launchUrl&quot;: &quot;&quot;,
        &quot;environmentVariables&quot;: {
          &quot;ASPNETCORE_ENVIRONMENT&quot;: &quot;Development&quot;
        },
        &quot;applicationUrl&quot;: &quot;https://localhost:5001;http://localhost:5000&quot;
      },
      &quot;Docker&quot;: {
        &quot;commandName&quot;: &quot;Docker&quot;,
        &quot;launchBrowser&quot;: true,
        &quot;launchUrl&quot;: &quot;{Scheme}://{ServiceHost}:{ServicePort}/&quot;,
        &quot;publishAllPorts&quot;: true,
        &quot;useSSL&quot;: true
      }
    }
  }
  </code></pre>