I have a web server on docker exposing port 8000 to port 8000 on my host. When I go to the public ip address of my linux host port 8000 I want the web server inside docker to be served up. I am running a EC2 container on AWS just in case there is any extra config.
What have you already done? What you describe sounds pretty routine.
I pulled my image down and started a container by running docker run -p 8000:8000 -t . That has not worked as when I go to the :8000 nothing happens. So then I tried configuring the iptables by running
iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j DNAT --to <host private ip address>:8000 and
iptables -A FORWARD -p tcp -d 172.31.29.241 --dport 8000 -j ACCEPT that also didn’t create any change. So what are the steps to get this working?
docker run -p 8000:8000 imagename should do it; you shouldn’t need to manually make changes to iptables.
What’s unusual about your environment? When you say “go to” and “nothing happens”, what does or doesn’t happen? Can you, for instance,
curl http://localhost:8000 from a shell on the host?
(Casting a total shot-in-the-dark guess, you’re calling the service from outside of Amazon, and your EC2 instance doesn’t have a security group that allows inbound connections on that port?)