Does “ports” on docker-compose.yml have the same effect as EXPOSE on Dockerfile?

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)