My docker-compose.override.yml
is as follows:
version: '3.4'
services:
helen.api:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=http://+:5000
ports:
- "5001:443"
- "5000:80"
volumes:
- ~/.aspnet/https:/root/.aspnet/https:ro
- ~/.microsoft/usersecrets:/root/.microsoft/usersecrets:ro
Dockerfile:
#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/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["MyProjectWebAPI/MyProject.API.csproj", "MyProjectWebAPI/"]
COPY ["MyProject.Globals/MyProject.Globals.csproj", "MyProject.Globals/"]
RUN dotnet restore "MyProjectWebAPI/MyProject.API.csproj"
COPY . .
WORKDIR "/src/MyProjectWebAPI"
RUN dotnet build "MyProject.API.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "MyProject.API.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "MyProject.API.dll"]
Docker-compose.yml
version: "3.4"
services:
helen.api:
image: ${DOCKER_REGISTRY-}helenapi
build:
context: .
dockerfile: HelenWebAPI/Dockerfile
When trying to access any URL of the Dockerized ASP.NET Web API, I get a 502 Bad Gateway Error:
2
Answers
Elastic Beanstalk’s proxy per defaults forwards traffic on port 5000. So either you should configure nginx to forward request to the port, your app listens on – 80, or you should make your app listen on port 5000.
your current config:
ingress traffic —> 80: nginx :any —5000 –> ??? 80: your container
should be:
ingress traffic —> 80: nginx :any —-80 —> 80: your container
or maybe easier to configure:
ingress traffic —> 80: ngnix :any —5000 —> 5000: your container
The latter can be easier changed by simply changing the environment property of your container.
I’m zero in .NET-terms, but look here:
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/dotnet-linux-platform-nginx.html
Perhaps the problem could be motivated that, according to the AWS documentation:
Please, following the suggested advice, try providing your own nginx container and the corresponding configuration in one of your docker-compose files. For example:
Microsoft as well as AWS provide excellent guides about how your
nginx.conf
file could look like:Note we are referencing the container
helen.api
as the server which is being proxied and that we are using port5000
as configured in theASPNETCORE_URLS
setting.