1. Dockerfile → EXPOSE
-
Purely documentation/metadata.
-
Doesn’t actually open or bind anything.
-
Other containers on the same network can still reach your app via
container_name:port
even if you don’tEXPOSE
it. -
Example: you can still
curl http://web:8080
inside another container, even if the Dockerfile doesn’t haveEXPOSE 8080
.
2. docker-compose.yml → expose:
-
Same as Dockerfile’s
EXPOSE
, but defined in Compose instead. -
Makes the port visible to other containers in the same Compose network.
-
Does not publish it to your host machine.
3. docker-compose.yml → ports:
-
This is the one that really matters if you want to access the container from outside Docker (e.g., browser, Postman, curl from host).
-
Maps container port → host port.
Example:
No comments:
Post a Comment