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
7
  • 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? Commented Oct 5, 2021 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?) Commented Oct 5, 2021 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 Commented Oct 5, 2021 at 20:13
  • oh wait, it's sh not bash Commented Oct 5, 2021 at 20:14
  • 2
    so.. restarting computer fixes this '__') RIP Commented Oct 6, 2021 at 19:46

1 Answer 1

5

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).

Sign up to request clarification or add additional context in comments.

2 Comments

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?).
On the first physical machine (Ubuntu version: 22.04 LTS, Docker version: 20.10.17, build 100c701), the curl http://localhost:<port> was returning me curl: (56) Recv failure: Connection reset by peer. I looked into that error, and thanks to this stackoverflow.com/questions/10285700/…, 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:<port> is reachable via curl, and accessible via web browser.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.