I have the following configuration in Raspberry Pi for iptables
pi@raspberrypi:~ $ sudo iptables --list
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere
REJECT all -- anywhere loopback/8 reject-with icmp-port-unreachable
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:http
ACCEPT tcp -- anywhere anywhere tcp dpt:https
ACCEPT tcp -- anywhere anywhere tcp dpt:http-alt
ACCEPT tcp -- anywhere anywhere tcp dpt:8181
ACCEPT tcp -- anywhere anywhere tcp dpt:8182
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
ACCEPT icmp -- anywhere anywhere
LOG all -- anywhere anywhere limit: avg 5/min burst 5 LOG level debug prefix "iptables denied: "
DROP all -- anywhere anywhere
Chain FORWARD (policy DROP)
target prot opt source destination
DOCKER-USER all -- anywhere anywhere
DOCKER-ISOLATION all -- anywhere anywhere
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
DOCKER all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
DROP all -- anywhere anywhere
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere
Chain DOCKER (1 references)
target prot opt source destination
ACCEPT tcp -- anywhere 172.17.0.2 tcp dpt:8181
Chain DOCKER-ISOLATION (1 references)
target prot opt source destination
RETURN all -- anywhere anywhere
Chain DOCKER-USER (1 references)
target prot opt source destination
RETURN all -- anywhere anywhere
and I have exposed port 8181 in Docker file. This device has a static IP of 192.168.100.20 and I can ping in to it from my host machine.
This is the docker file configuration
FROM myapp
COPY . /app
RUN pip install -e /app
WORKDIR /app/node
EXPOSE 8181
ENTRYPOINT [ "myapp", "run" ]
I am running as docker run -p 8181:8181 <image_id>
But when I tried to access it by its IP, it says address not found and when I do a port scan, I'm getting the following result
Discovered closed port 8181/tcp on 192.168.100.20
8181/tcp closed intermapper conn-refused
What prevents accessing it from outside the Raspberry Pi device ?
-p 192.168.100.20:8181:8181
or, alternatively,-p 0.0.0.0:8181:8181
172.17.0.2:8181
docker inspect <container_id>
. In any case, if that is the container IP then the firewall/networking is not the problem, but your image does not have anything bound to that port, or, you have configured the image to block that port. Even though it is exposed inDockerfile
, there is "no one home" so to speak.