Docker Community Forums

Share and learn in the Docker community.

Access docker port from outside of host

(Bmeeder22) #1

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.

(David Maze) #2

What have you already done? What you describe sounds pretty routine.

(Bmeeder22) #3

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 --dport 8000 -j ACCEPT that also didn’t create any change. So what are the steps to get this working?

(David Maze) #4

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

(Bmeeder22) #5

Yes I can curl http://localhost:8000 from a shell on the host but how do I configure the AWS server so I can go to :8000 and get the website that is being served? Currently when I curl http://:8000 nothing happens and the connection eventually times out.