expose in dockerfile and docker-compose, and ports
tags: learning docker diff-between
content
what’s the difference between EXPOSE in Dockerfile, expose in docker-compose:
- in Dockerfile,
EXPOSEdoes not have any actual functionality other than documentation - in docker-compose,
exposeis actually exposing a port of a container to other containers- e.g.,
expose: 80it makes port 80 reachable to other containers
- e.g.,
also in docker-compose, there is ports option
- it links a port on the host machine to a port in a container
ports: "5173:80"means that docker maps5173on host machine to the container’s port 80- i.e., port 80 inside the container can be reached with host’s 5173
- docker is doing port forwarding with
ports