Failed to connect to 172.17.0.2 port 8080: Connection refused

Hello everybody!!

I have created a container httpd as follows:

docker run -d -p 8080:80 --name web httpd

I run correctly:

docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b368080968e0 httpd “httpd-foreground” 2 minutes ago Up 2 minutes 0.0.0.0:8080->80/tcp, :::8080->80/tcp web

I execute:
docker inspect web | grep ddress

  • “LinkLocalIPv6Address”: “”,*
  •        "SecondaryIPAddresses": null,*
    
  •        "SecondaryIPv6Addresses": null,*
    
  •        "GlobalIPv6Address": "",*
    
  •        "IPAddress": "172.17.0.2",*
    
  •        "MacAddress": "02:42:ac:11:00:02",*
    
  •                "IPAddress": "172.17.0.2",*
    
  •                "GlobalIPv6Address": "",*
    
  •                "MacAddress": "02:42:ac:11:00:02",*
    

But when I execute the command: curl 172.17.0.2:8080
curl: (7) Failed to connect to 172.17.0.2 port 8080: Connection refused

If I use localhost no problem, but I can not use the ip of the container.

Thanks in advance

Hello and welcome :slight_smile:

with -p 8080:80 you have mapped the container’s port 80 to your host’s port 8080. It is a kind of port-forwarding.

So you can connect to the container’s ip with port 80 (usually only used for troubleshooting, because after a container-restart the ip-address might be different).

Or you can connect to your host’s port 8080 (i.e. http://<host-ip>:8080/ or maybe http://localhost:8080/)

So not being able to connect to http://<container-ip>:8080/ is normal and working as expected.

1 Like

Thanks to you and all the amazing docker community