dotnet-docker icon indicating copy to clipboard operation
dotnet-docker copied to clipboard

Getting the following exception any time I try to run the dotnet sample app from docker hub: Unhandled exception. System.IO.IOException: Failed to bind to address http://[::]:80: address already in use. ---> Microsoft.AspNetCore.Connections.AddressInUseException: Address in use

Open ZeeshanAdilButt opened this issue 1 year ago • 3 comments

Describe the Bug

Any time I try to run the docker sample app from the Microsoft Docker Hub Documentation here: https://hub.docker.com/_/microsoft-dotnet-samples/

for the command:

docker run -it --rm -p 8800:80 --name aspnetcore_sample mcr.microsoft.com/dotnet/samples:aspnetapp

I get the following error:

Unhandled exception. System.IO.IOException: Failed to bind to address http://[::]:80: address already in use. ---> Microsoft.AspNetCore.Connections.AddressInUseException: Address in use ---> System.Net.Sockets.SocketException (98): Address in use at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError, Boolean , String ) at System.Net.Sockets.Socket.DoBind(EndPoint, SocketAddress) at System.Net.Sockets.Socket.Bind(EndPoint) at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransportOptions.CreateDefaultBoundListenSocket(EndPoint) at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketConnectionListener.Bind() --- End of inner exception stack trace ---

Steps to Reproduce

Simply go to to this link: https://hub.docker.com/_/microsoft-dotnet-samples/

and pick the Container sample: Run a web application sample and try to run the following command as per the instructions there:

docker run -it --rm -p 8000:80 --name aspnetcore_sample mcr.microsoft.com/dotnet/samples:aspnetapp

and you should be able to receive the same excpetion

Output of docker version

Client: Cloud integration: v1.0.31 Version: 20.10.24 API version: 1.41 Go version: go1.19.7 Git commit: 297e128 Built: Tue Apr 4 18:28:08 2023 OS/Arch: windows/amd64 Context: default Experimental: true

Server: Docker Desktop 4.18.0 (104112) Engine: Version: 20.10.24 API version: 1.41 (minimum version 1.12) Go version: go1.19.7 Git commit: 5d6db84 Built: Tue Apr 4 18:18:42 2023 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.6.18 GitCommit: 2456e983eb9e37e47538f59ea18f2043c9a73640 runc: Version: 1.1.4 GitCommit: v1.1.4-0-g5fd4c4d docker-init: Version: 0.19.0 GitCommit: de40ad0

Output of docker info

Client: Context: default Debug Mode: false Plugins: buildx: Docker Buildx (Docker Inc., v0.10.4) compose: Docker Compose (Docker Inc., v2.17.2) dev: Docker Dev Environments (Docker Inc., v0.1.0) extension: Manages Docker extensions (Docker Inc., v0.2.19) init: Creates Docker-related starter files for your project (Docker Inc., v0.1.0-beta.2) sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc., 0.6.0) scan: Docker Scan (Docker Inc., v0.25.0) scout: Command line tool for Docker Scout (Docker Inc., v0.9.0)

Server: Containers: 1 Running: 0 Paused: 0 Stopped: 1 Images: 22 Server Version: 20.10.24 Storage Driver: overlay2 Backing Filesystem: extfs Supports d_type: true Native Overlay Diff: true userxattr: false Logging Driver: json-file Cgroup Driver: cgroupfs Cgroup Version: 2 Plugins: Volume: local Network: bridge host ipvlan macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog Swarm: inactive Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc Default Runtime: runc Init Binary: docker-init containerd version: 2456e983eb9e37e47538f59ea18f2043c9a73640 runc version: v1.1.4-0-g5fd4c4d init version: de40ad0 Security Options: seccomp Profile: default cgroupns Kernel Version: 5.15.90.1-microsoft-standard-WSL2 Operating System: Docker Desktop OSType: linux Architecture: x86_64 CPUs: 8 Total Memory: 15.53GiB Name: docker-desktop ID: JB3P:WTLF:JOAB:5FXL:DORD:P6GC:SVJW:22SB:MVNH:5DBU:TNLY:W3I3 Docker Root Dir: /var/lib/docker Debug Mode: false HTTP Proxy: http.docker.internal:3128 HTTPS Proxy: http.docker.internal:3128 No Proxy: hubproxy.docker.internal Registry: https://index.docker.io/v1/ Labels: Experimental: false Insecure Registries: hubproxy.docker.internal:5555 127.0.0.0/8 Live Restore Enabled: false

I'd appreciate any help with this. Thanks

ZeeshanAdilButt avatar Apr 17 '23 23:04 ZeeshanAdilButt

Hi, I can't reproduce this issue using Docker with the WSL2 backend. Please make sure you are running the latest version of the samples by running docker pull mcr.microsoft.com/dotnet/samples:aspnetapp.

You can try changing the port directly by setting the ASPNETCORE_URLS environment variable when you run the container: docker run -it --rm -p 8000:8000 -e ASPNETCORE_URLS=http://+:8000 --name aspnetcore_sample mcr.microsoft.com/dotnet/samples:aspnetapp. I'm not sure what would cause port 80 to be occupied in your container but I'm also not sure if WSL2 specifically does anything weird with ports.

lbussell avatar Apr 18 '23 16:04 lbussell

hey @lbussell thanks for sharing the insights on your end, I provisioned a new Linux VM and tried to run the same command and the aspnet app on port 80 inside the container and it works, while the same seems to not work on my Windows machine.

I have shared all the information from my docker running on my windows with a WSL2 backend, I also have some ubuntu distros running on my WSL which I know is a completely separate thing from docker but still some info that might help? idk

About your concern on the image being latest, I have the latest image, for your info:

Digest: sha256:41a7303e69548a72930def39c59bf3fc86abb0d518a487867ab574a263856ebf Status: Image is up to date for mcr.microsoft.com/dotnet/samples:aspnetapp mcr.microsoft.com/dotnet/samples:aspnetapp

any idea on what might be the issue here? appreciate any help

ZeeshanAdilButt avatar Apr 21 '23 22:04 ZeeshanAdilButt

any idea on what might be the issue here? appreciate any help

I compared my docker info and docker version commands to yours and everything looks exactly the same. I can only guess that it's some issue with Windows / your machine's configuration. Could you try running a different (non-.NET) container that runs on port 80 and see if that also fails?

lbussell avatar Apr 24 '23 17:04 lbussell