2

OS: Ubuntu 20.04 LTS

Docker version 20.10.7, build 20.10.7-0ubuntu1~20.04.2

Tried this (minimal way to reproduce), the previous day it works normally:

docker run --name nginx1 -p 8089:80 -d nginx:alpine

Works normally:

docker ps

CONTAINER ID   IMAGE          COMMAND                  CREATED         
74faabf44b8e   nginx:alpine   "/docker-entrypoint.…"   5 minutes ago   

STATUS         PORTS                                       NAMES
Up 5 minutes   0.0.0.0:8089->80/tcp, :::8089->80/tcp       nginx1

curl inside docker works:

docker exec -it 74faabf44b8e sh

/ # curl localhost
<!DOCTYPE html>
<html>
<head>
....

But when accessed from the host:

netstat -antpel | grep 8089
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 0.0.0.0:8089            0.0.0.0:*               LISTEN      0          82748695   -                   
tcp6       0      0 :::8089                 :::*                    LISTEN      0          82751546   - 

curl -v localhost:8089
*   Trying 127.0.0.1:8089...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8089 (#0)
> GET / HTTP/1.1
> Host: localhost:8089
> User-Agent: curl/7.68.0
> Accept: */*
> 
--> stuck without a response, after a while:
* Recv failure: Connection reset by peer
* Closing connection 0
curl: (56) Recv failure: Connection reset by peer

What's the possible cause of this?
This also doesn't work for another container (PostgreSQL), seems the docker-proxy does not forward back the response from docker?

already tried:

  • reinstall docker.io
  • delete all containers and re-create
  • docker network prune
Kokizzu
  • 24,974
  • 37
  • 137
  • 233
  • Does `localhost` resolve to e.g. `127.0.0.1` on your machine? What does `nslookup localhost` return or `cat /etc/hosts`? What happens if you `curl -v 127.0.0.1:8089`? – DazWilkin Oct 05 '21 at 19:45
  • I think Alpine does not include bash so it's curious that your `docker exec` works (using bash) on an Alpine image (unless it's aliased?) – DazWilkin Oct 05 '21 at 19:46
  • yes, localhost = 127.0.0.1 on my machine `ping localhost PING localhost (127.0.0.1) 56(84) bytes of data. 64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.039 ms` @DazWilkin the result is connection result by peer after a while – Kokizzu Oct 05 '21 at 20:13
  • oh wait, it's `sh` not `bash` – Kokizzu Oct 05 '21 at 20:14
  • A guess: could you try `curl --verbose --ipv4 localhost:8089` to force it to bind to the IPv4 endpoint? – DazWilkin Oct 05 '21 at 20:40
  • still the same @DazWilkin – Kokizzu Oct 05 '21 at 21:12
  • 2
    so.. restarting computer fixes this '__') RIP – Kokizzu Oct 06 '21 at 19:46

1 Answers1

3

Ubuntu version: 22.04 LTS

Docker version: 20.10.17, build 100c701

Installation procedure: https://docs.docker.com/engine/install/ubuntu/

I am encountering the same problem as you on more recent versions of Ubuntu & Docker: Everything seems to be working fine except that the host is not able to reach the container on port, as defined by the -p <docker-host-port>:<docker-container-port> option.

curl http://localhost:<port> works from within the container, but not from outside despite port binding ...

I tried to restart docker daemon, restart machine, remove container, recreate container, remove image, recreate image, uninstall completely docker, reinstall docker from scratch. I just don't understand why Docker is acting funky like this on this specific instance (Ubuntu 22.04 + Docker).

  • I just tried on a different physical machine running: Ubuntu version: **20.04.4 LTS** (previous Ubuntu LTS version) and Docker version: 20.10.17, build 100c701 (same Docker version). Everything works as expected! That tells me that there is a problem, either with Ubuntu 22.04 LTS, or with the first physical machine (hardware?). – Edouard Barthélémy Jul 27 '22 at 14:48
  • 1
    On the first physical machine (Ubuntu version: 22.04 LTS, Docker version: 20.10.17, build 100c701), the `curl http://localhost:` was returning me `curl: (56) Recv failure: Connection reset by peer`. I looked into that error, and thanks to this https://stackoverflow.com/questions/10285700/curl-error-recv-failure-connection-reset-by-peer-php-curl, I found out that it was a VPN issue. Probably something that has to do with MTU (Maximum Transmission Unit) size of packets ... So, when disabling VPN, `http://localhost:` is reachable via curl, and accessible via web browser. – Edouard Barthélémy Jul 27 '22 at 15:06