Easy, straightforward, robust way to make host port available to Docker container?

It is really easy to mount directories into a docker container. How can I just as easily “mount a port into” a docker container?

Example:

  • Howto assign second ip to docker container with ip:port:port
  • Docker+SSH, how to transfer docker images from one host to another securely on a regular basis?
  • Docker mysql image: periodic access denied for root
  • Weird behaviour of boto inside docker
  • Docker do not work from build remotely at Jenkins slave. What' the reason?
  • Docker for Windows: cannot assign requested address
  • I have a MySQL server running on my local machine. To connect to it from a docker container I can mount the mysql.sock socket file into the container. But let’s say for some reason (like intending to run a MySQL slave instance) I cannot use mysql.sock to connect and need to use TCP.

    How can I accomplish this most easily?

    Things to consider:
    I may be running Docker natively if I’m using Linux, but I may also be running it in a VM if I’m on Mac or Windows, through Docker Machine or Docker for Mac/Windows (Beta). The answer should handle both scenarios seamlessly, without me as the user having to decide which solution is right depending on my specific Docker setup.
    Simply assigning the container to the host network is often not an option, so that’s unfortunately not a proper solution.

    Potential solution directions:
    1) I understand that setting up proper local DNS and making the Docker container (network) talk to it might be a proper, robust solution. If there is such a DNS service that can be set up with 1, max 2 commands and then “just work”, that might be something.
    2) Essentially what’s needed here is that something will listen on a port inside the container and like a sort of proxy route traffic between the TCP/IP participants. There’s been discussion on this closed Docker GH issue that shows some ip route command-line magic, but that’s a bit too much of a requirement for many people, myself included. But if there was something akin to this that was fully automated while understanding Docker and, again, possible to get up and running with 1-2 commands, that’d be an acceptable solution.

  • Atom editor PHP link from Docker container
  • Docker app deployment hangs on Marathon, fails on Mesos
  • docker+elasticsearch: access is denied when creating the log file
  • How can you run multiple docker containers from your computer, and have each use a different IP (using a VPN)?
  • How to run custom Docker file?
  • Can't connect to Postgres container with Docker Compose from Sequelize
  • One Solution collect form web for “Easy, straightforward, robust way to make host port available to Docker container?”

    I think you can run your container with --net=host option. In this case container will bind to the host’s network and will be able to access all the ports on your local machine.

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