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.