docker,

Docker Compose: expose vs ports

Jun 14, 2023 · 1 min read · Post a comment

At first sight expose and ports kinda look basically the same thing right, but there is a subtle keep difference. Here’s the deal.

Prerequisites

  • Docker
  • Docker Compose

Solution

  • expose: exposes ports internally within the Docker compose stack network. Cannot be accessible from the host machine or external network. Used only by the internal services being part of the same Docker Compose stack for example.
  • ports: publish and maps ports from the container to the host machine. Ports accessible from the host though or external network.

Conclusion

In case you face any issues, feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.