Why and when use EXPOSE?

I really don’t understand the point of using EXPOSE.

If I want to talks between containers I use named networks with bridge, if I want to access from outside I use port publish/mapping.

Why “expose” ports?

Thanks.

Please look at this old thread

1 Like
  • EXPOSE` is a way of documenting
  • –publish(or-p` ) is a way of mapping a host port to a running container port
1 Like

Also, if there is ports that have been defined in EXPOSE, you can use “docker run -P” and it will auto map the ports that is listed in the image

1 Like