Does declaring on a docker-compose.yml:
ports:
- \"3306:3306\"
and on Dockerfile:
EXPOSE 3306
have the same
No: EXPOSE
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.
See Dockerfile EXPOSE:
The
EXPOSE
instruction informs Docker that the container listens on the specified network ports at runtime.
EXPOSE
does not make the ports of the container accessible to the host. To do that, you must use the-p
flag to publish a range of ports.
That is what the docker-compose.yml ports section does. It maps container port to the host.