docker-compose 404 page not found AspNet running inside Docker Container


Question: Why am I getting a 404 page not found in Docker Asp.Net Core Application even when I verified tested on the Development Server and everything is working?


Login to See the Rest of the Answer

Answer:
The problem might be Hst Middleware that adds Strict-Transport-Security Header to the HTTP Response if your application is using this Middleware and you have configured your application to listen to incoming traffic at a none HTTPS Port in the docker-compose.yml file you might have problems. 

On the Development Server, there is a chance that Visual Studio 2022 is using a Self-Signed Certificate to serve HTTPS Requests, hence inside the Docker Container, you need to do extra work to make the HTTP Communication Encrypted End-To-End. This means that the Application should serve encrypted files from the get-go.

FYI: If the above described is the case, then you might not even access the application running in Docker Container without configuring HTTPS Protocol. 

Steps to Resolve the issue:

1. Make sure that the encryption is End-To-End meaning the application in the Docker Container should listen only on the HTTPS Port and not HTTP.

[Note]: If you use a Reverse Proxy to Load Balance traffic make sure that the Reverse Proxy actually supports HTTP Communication with Upstream (Back-End: Traffic going to your Docker Container) otherwise the HTTPS communication will be terminated and you will have another layer of troubleshooting not knowing what is going on.

2. Make sure that the Dockerfile has the HTTPS port Mapped correctly to inside Docker Container Container
    FYI: The configuration in Dockerfile might be overridden by the dockercompose.yml Environment Variable or Port Forwarding.

3. Make sure you have mapped the Certificates Folder as ASPNETCORE_Kestrel_Certificates_Default_Path and Default_Password this lets the application running inside Docker Container know of the Certificates and then use them to serve requests. If this is not done right the application will not respond instead it will throw an error that it can't the Certificates.

In order to map a Certificate to an Asp.Net Core Application running inside Docker Container, use the Environment Variable Section of the docker-compose directive to pass in Variables to Docker Container, see the code below:

 - ASPNETCORE_Kestrel__Certificates__Default__Password=YourPassword
 - ASPNETCORE_Kestrel__Certificates__Default__Path=/LocationToVolumeWithTheCertificate/Certiticate.pfx

Remember, the certificate can be self-signed or purchased, just make sure to validate on every step to make sure the configuration is working.


[Note]: If the above did not work, then the issue might be with your application itself, make sure you turn on logging to the Console so that you see errors and pick it up from there.






For peering opportunity Autonomouse System Number: AS401345 Custom Software Development at ErnesTech Email AddressContact: [email protected]