I'm stuck with getting port mapping to work with a docker instance I've built. curl localhost
in the docker container shows the application is working fine, but curl from host returns:
* Rebuilt URL to: 127.0.0.1/
* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.35.0
> Host: 127.0.0.1
> Accept: */*
>
* Empty reply from server
* Connection #0 to host 127.0.0.1 left intact
curl: (52) Empty reply from server
I've exposed the port with -p
flag. I've tried mapping all sorts of different ports.
How might I debug this? What are common problems with port mapping?
If you're doing curl
outside of the container - it won't work. If I understand you correctly then you have several variants:
Use command docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' $INSTANCE_ID
- more on Docker Inspect.
Use command docker port $CONTAINER_NAME
- more on Docker Port.
Execute command docker inspect -f '{{ .NetworkSettings.IPAddress }}' <CONTAINER_NAME>
. It should show you internal IP-address and then try to curl <IP_FROM_COMMAND>:<PORT>
.