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

Does declaring on a docker-compose.yml:

 - "3306:3306"

and on Dockerfile:

  • Docker bridge over IPSec - Connection reset by peer with Tomcat (but not Nginx)
  • Is it possible to restrict access to lxc containers?
  • How can I Provide Permissions to a PHP Docker Image and Host VOLUME?
  • docker disk space grows faster than container's
  • How can I automatically run a docker container on/after image build?
  • file system issue when i use vagrant+docker on windows
  • EXPOSE 3306

    have the same effect?

  • Docker how to change repository name or rename image?
  • Howto persist MongoDB - data of a running Docker container in a new image?
  • docker-compose images volumes
  • Collect UDP(Gelf) messages and forward with TCP to logstash
  • Connecting go and postgres with docker-compose
  • Volume changes not persistent after “docker-compose run” command (Django's collectstatic)
  • One Solution collect form web for “Does “ports” on docker-compose.yml have the same effect as EXPOSE on Dockerfile?”

    No: EXPOSE (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.

    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.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.