Restrict published port to a specific container with Docker

I have two Docker images :

  • a tomcat image, exposing the port 8080
  • a mysql image, exposing the port 3306

I run two containers using these images, linking mysql with tomcat :

  • How to map the IP address of docker container to another container dynamically
  • Postgresql raises 'data directory has wrong ownership' when trying to use volume
  • Docker map drive from Docker container to Linux to Windows host
  • How can you run a Docker container if it doesn't exist yet, or start it if it does?
  • Add Logtrail plugin to kibana to see the logs in kibana ui - openshift/origin-aggregated-logging
  • how to connect to container in docker stack deploy
  • docker run -itd -p 3306:3306 --name mysql mysql
    docker run -itd -p 8080:8080 --link mysql:mysql --name tomcat tomcat

    When I do that, tomcat communication with mysql works fine, and my tomcat and mysql containers are available on the server host, respectively on ports 8080 and 3306.

    Now I would like the port 3306 to be closed on the server host and only available for the tomcat container. How can I do that?

  • cqlsh to Cassandra single node running in docker
  • rename enviromental variables from linking dockers
  • Docker Server for Multiple Users
  • Docker Registry vs Docker “Trusted” Registry
  • How is the rootfs size of docker container is decided?
  • Sorl4 failing to index when using EBS volume in ECS
  • One Solution collect form web for “Restrict published port to a specific container with Docker”

    In that case you can simply skip the -p parameter like:

    docker run -itd --name mysql mysql
    docker run -itd -p 8080:8080 --link mysql:mysql --name tomcat tomcat
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.