3

I know I can EXPOSE a port (e.g. 8888) in dockerfile. With this dockerfile I can build a image, then I rundocker run --name container1 -p 8888:8888 image. Via this method I can access port 8888 in the container.

The second way I don't EXPOSE any port from dockerfile. With this dockerfile I can build image2, then I rundocker run --name container2 -p 8888:8888 image2.

I wanna ask what is the difference between them ?

I find something strange.

In container1 I run jupyter notebook --port 8888. I can both access the port 8888 from the host running the container (localhost:8888) and the computer(hostip:8888) in the same local network

In container2 I run jupyter notebook --port 8888. I can access the port 8888 from the host running the container (localhost:8888), but I can not access the port 8888 via hostip:8888 from the computer in the same local network.

Li Zhang
  • 113
  • 1
  • 10
  • 2
    from the doc at https://docs.docker.com/engine/reference/builder/#/expose `EXPOSE does not make the ports of the container accessible to the host` – user2915097 Oct 31 '16 at 14:35
  • 2
    Possible duplicate of [Difference between "expose" and "publish" in docker](http://stackoverflow.com/questions/22111060/difference-between-expose-and-publish-in-docker) – Roman Oct 31 '16 at 15:39

0 Answers0