Friday, 5 September 2025

docker expose, docker-compose expose

 

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’t EXPOSE it.

  • Example: you can still curl http://web:8080 inside another container, even if the Dockerfile doesn’t have EXPOSE 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:

    ports: - "8080:80" # host:container

No comments:

Post a Comment