Docker Community Forums

Share and learn in the Docker community.

All ports exposed in Container?


(Jhannwong) #1

I run an Ubuntu inside a VirtualBox VM on a Mac OS.

I create a container. I place a server inside it that listens on port 8000. Did not export port 8000.
In the host (Ubuntu), I use Firefox to go to localhost:8000 . No access. Expected behavior.

Then I use the container’s IP address “172.17.0.2:8000”. Access granted. I’m surprised.

Newbie here. Does it have anything to do with phusion/baseimage?


(Ranjandas) #2

Hi @jhannwong

There is nothing wrong with the phusion baseimage.
The one you saw is the expected behaviour. If you dont expose the port using -p/-P while running container, the port will only be accessible using the container IP address.

Regards


(Jhannwong) #3

In which case, that container IP should only be accessible from the Docker’s host and not from outside of the host. Correct?

Thanks for the guidance. Thanks for saving my sanity. :slight_smile:


(Ranjandas) #4

You are right. container IP will be only accessible from docker host.

:+1: