At first sight
ports kinda look basically the same thing right, but there is a subtle keep difference. Here’s the deal.
- Docker Compose
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.
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.