Docker Community Forums

Share and learn in the Docker community.

Can't access docker containers from host


(Des7) #1

I am new to both docker and networking in general so bare with me. I have multiple docker (v 18.03.1 ce) containers running splunk on port 80 in a centos7 VM. I need to be able to directly access each container from outside the VM. I started each container with a different name and port mapping like this:

docker run --name container1 -p 8884:80 splunkimage
docker run --name container2 -p 8885:80 splunkimage
docker run --name container3 -p 8886:80 splunkimage

and I added a new rule in iptables:

iptables -A FORWARD -i docker0 -o eth0 -j ACCEPT
iptables -A FORWARD -i eth0 -o docker0 -j ACCEPT

Here are the IPs:
docker0: 172.17.0.1
eth0: 192.168.1.5
VM IP: 172.29.0.9

The problem is I cannot access the splunk page when going to 172.29.0.9:8884 from my host machine. It says “webpage not available.” So then I tried 192.168.1.5:8884 and it says “no data received.” I clearly don’t know what I’m doing so can anyone help? (and yes the ports I used are actually open and available)


(Marcelop3251) #2

Hello, I believe that if you put --network host able to access the containers from outside the VM

For example.

docker run --name container1 -p 8884:80 --network host splunkimage

I hope I have been able to help.


(Des7) #3

Thanks for your response but that doesn’t work for me. As mentioned I have multiple docker containers running splunk on the same host so if I bind the network to the host it will make the ports “busy” and I won’t be able to start the other containers because splunk needs to run on those same ports. I am specifically asking about how to make the bridge network work. Each container has a different ip so want to use port forwarding to be able to access them all on my host ip. So I want to be able to go to 172.29.0.9:8884 for container 1 172.29.0.9:8885 for container 2 etc…