Docker port forwarding not working
A very common problem can be this:
Bind your app inside Docker to 0.0.0.0, not to 127.0.0.1 address to let Docker reach the app inside container.
Port 7000
on the host is redirecting to port 8000
in the container, but is anything listening on that port in the container?
Your docker run
command is a bit odd: -it
is for running a container interactively with a terminal attached; -d
is for running detached, in the background; bash
at the end overrides whatever the image configures as the startup command, which is why I think there's nothing listening on port 8000
.
Try running the simplest NGINX container with this:
docker run -d -p 8081:80 nginx:alpine
And then verify you can get to the homepage:
curl http://localhost:8081
If that's working then I'd look at how you're running your image.
Partial Answer:
Now I solved this problem partially, While i try without bash in create a container and change my port to 3000(-p 3000:80) it worked for me.
Before Command:
docker run -it -d --name containerName -h www.myhost.net -v /var/www/html -p 3000:80 --net mynetwork --ip 172.11.0.10 --privileged myimagename bash
After Command:
docker run -it -d --name containerName -h www.myhost.net -v /var/www/html -p 3000:80 --net mynetwork --ip 172.11.0.10 --privileged myimagename
Then,
execute the container with bin/bash
docker exec -it containerName bin/bash
Now , works locally Connected Another machine.
hostmachineip:3000 I don't know docker have any port restrictions.But This solution works for me.