Difference Between Expose and Ports in Docker Compose
Bookmark Notes #
tags :
URL #
Clipped text #
In this article, we covered part of the networking configurations in the Docker Compose. We analyzed and compared port configuration using the expose and ports sections.
The expose section allows us to expose specific ports from our container only to other services on the same network. We can do this simply by specifying the container ports.
The ports section also exposes specified ports from containers. Unlike the previous section, ports are open not only for other services on the same network, but also to the host. The configuration is a bit more complex, where we can configure the exposed port, local binding address, and restricted protocol. Finally, depending on our preferences, we can choose between the two different syntaxes.