Does “ports” on docker-compose.yml have the same effect as EXPOSE on Dockerfile?
Does declaring on a docker-compose.yml:
ports: - "3306:3306"
and on Dockerfile:
have the same effect?
One Solution collect form web for “Does “ports” on docker-compose.yml have the same effect as EXPOSE on Dockerfile?”
EXPORT does not exist) only opens the port in the container, making it accessible by other containers.
"3306:3306" will publish the port on the host, making the same port accessible from the host.
EXPOSEinstruction informs Docker that the container listens on the specified network ports at runtime.
EXPOSEdoes not make the ports of the container accessible to the host. To do that, you must use the
-pflag to publish a range of ports.
That is what the
docker-compose.yml ports section does. It maps container port to the host.