Search code examples
dockerdocker-container

ERR_EMPTY_RESPONSE from web browser when accessing a URL in A Docker container


I have set up a Docker container with a web server on port 5000 (HTTP).

What doesn't work:

  • When I try to access the web service from a web browser on my PC (which hosts the Docker), I get the error 'ERR_EMPTY_RESPONSE'
  • I have tried connecting with: http://localhost:5000, http://127.0.0.1:5000, http://<PC_IP_Address:5000, http://<Docker_Container_IP_Address>:5000, http://<Ethernet_adapter_vEthernet_(WSL)_IP_Address:5000>, but get the same error ('ERR_EMPTY_RESPONSE') with all these

What does work:

  • From my PC, I can run the container and telnet to 'localhost 5000' (it connects and shows a blank screen). When the container is offline, I cannot telnet to 'localhost 5000'.
  • From bash on the Docker container, I can run 'curl http://localhost:5000' and it returns HTML

These tests prove that the web service is running and there are no firewall issues.

The Docker image was built with:

# syntax=docker/dockerfile:1
##This is the Long Time Support (LTS) version, runs on Debian (https://hub.docker.com/_/node)
FROM node:16.16.0


# install app dependencies
#Install .net (https://learn.microsoft.com/en-us/dotnet/core/install/linux-debian)
##Add the Microsoft package signing key to your list of trusted keys and add the package repository.
RUN wget https://packages.microsoft.com/config/debian/11/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
RUN dpkg -i packages-microsoft-prod.deb
RUN rm packages-microsoft-prod.deb
##Install the runtime
RUN apt-get update && \
    apt-get install -y aspnetcore-runtime-6.0


# install app


# final configuration
ENV Authentication__FB__ClientId=myKey
ENV Authentication__FB__ClientSecret=myKey
ENV Authentication__Google__ClientId=myKey.apps.googleusercontent.com
ENV Authentication__Google__ClientSecret=myKey
ENV Authentication__Microsoft__ClientId=myKey
ENV Authentication__Microsoft__ClientSecret=myKey
ENV SendGridKey=myKey
ENV StorageConnectionString__blob=DefaultEndpointsProtocol=https;AccountName=mysite;AccountKey=myKey==;BlobEndpoint=https://mysite.blob.core.windows.net/;TableEndpoint=https://mysite.table.core.windows.net/;QueueEndpoint=https://mysite.queue.core.windows.net/;FileEndpoint=https://mysite.file.core.windows.net/
ENV Stripe__PublishableApiKey=mySecret
ENV Stripe__SecretApiKey=mySecret
ENV Stripe__WebhookSecret=mySecret
ENV Url=localhost
ENV VaultUri=https://mysite.vault.azure.net/

EXPOSE 5000

I have also run within the container:

cd wwwroot
npm install
curl -sL https://aka.ms/InstallAzureCLIDeb | bash
az login
dotnet Web.dll

The Container is started with both port 5000 mapped as port 5000.

Please can you let me know why I can't see the HTML page from my PC's web browser.


Solution

  • I had to enter this from bash:

    dotnet Web.dll --urls "http://:5000;https://:5001"