Dotnet-docker: Can't connect to a .net core app running in a container

Created on 11 Sep 2017  路  3Comments  路  Source: dotnet/dotnet-docker

Steps to reproduce the issue

  1. Use the following Dockerfile:
FROM microsoft/dotnet:1.1.2-sdk

RUN apt-get update && apt-get install -y --no-install-recommends netcat

WORKDIR /site

RUN dotnet new web && dotnet restore && dotnet build

EXPOSE 5000

CMD ["dotnet", "run"]
#CMD while true; do echo 'Hello World!' | nc -l -p 5000; done
  1. build image: sudo docker build -t netcorewebtest .
  2. run it: sudo docker run -itp 5000:5000 netcorewebtest
  3. in another session try connecting to it: lynx http://localhost:5000/ or telnet localhost 5000 (followed by GET / HTTP/1.1 and two returns)

Expected behavior

Get the "Hello World!" response from the web app

Actual behavior

Lynx:

$ lynx http://localhost:5000/

Looking up localhost:5000
Making HTTP connection to localhost:5000
Alert!: Unable to connect to remote host.

lynx: Can't access startfile http://localhost:5000/

telnet:

$ telnet localhost 5000
Trying 127.0.0.1...
Trying ::1...
telnet: Unable to connect to remote host: Network is unreachable

Additional information (e.g. issue happens only occasionally)

If I use the commented CMD line that runs netcat instead of dotnet run, I am able to connect from the host machine to it with telnet.

Output of docker version

Client:
 Version:      17.06.2-ce
 API version:  1.30
 Go version:   go1.8.3
 Git commit:   cec0b72
 Built:        Tue Sep  5 20:00:28 2017
 OS/Arch:      linux/amd64

Server:
 Version:      17.06.2-ce
 API version:  1.30 (minimum version 1.12)
 Go version:   go1.8.3
 Git commit:   cec0b72
 Built:        Tue Sep  5 19:59:22 2017
 OS/Arch:      linux/amd64
 Experimental: false

Output of docker info

Containers: 62
 Running: 0
 Paused: 0
 Stopped: 62
Images: 95
Server Version: 17.06.2-ce
Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 175
 Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 6e23458c129b551d5c9871e5174f6b1b7f6d1170
runc version: 810190ceaa507aa2727d7ae6f4790c76ec150bd2
init version: 949e6fa
Kernel Version: 3.16.0-4-amd64
Operating System: Debian GNU/Linux 8 (jessie)
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 7.682GiB
Name: htpc
ID: U7QW:ANTW:GNW6:AWMD:T4PZ:2VA3:K26E:37XR:RT5X:LAOR:YPCN:B5EU
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

WARNING: No memory limit support
WARNING: No swap limit support
WARNING: No kernel memory limit support
WARNING: No oom kill disable support
WARNING: No cpu cfs quota support
WARNING: No cpu cfs period support
question

Most helpful comment

ASP.NET Core doesn't listen to external endpoints by default. You have to configure this. e.g.

ENV ASPNETCORE_URLS http://+:80
docker run -it -p 5000:80 netcorewebtest

Consider using FROM microsoft/aspnetcore-build:1.1.2 instead. This automatically sets up this environment variable for you. https://github.com/aspnet/aspnet-docker/blob/master/1.1/jessie/sdk/Dockerfile#L4

All 3 comments

ASP.NET Core doesn't listen to external endpoints by default. You have to configure this. e.g.

ENV ASPNETCORE_URLS http://+:80
docker run -it -p 5000:80 netcorewebtest

Consider using FROM microsoft/aspnetcore-build:1.1.2 instead. This automatically sets up this environment variable for you. https://github.com/aspnet/aspnet-docker/blob/master/1.1/jessie/sdk/Dockerfile#L4

Yup, that was the reason. Should have thought of that. Thank you.

Save me a lot of time. Thanks.

Was this page helpful?
0 / 5 - 0 ratings