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?


  • docker volume: subdirectories are missing
  • Kubernetes how to make Deployment to update image
  • certbot.main:Exiting abnormally
  • How to run linux command before starting up git bash terminal
  • Not able to start Docker daemon
  • Uninstall applications within docker?
  • 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.

  • Using SSH Hadoop inside docker container with non-privileged user
  • Issue with docker push on local registry https access to ressource denied
  • How do I get the container ID of a non-running container?
  • Cloud foundry scale
  • What are the best practices for tagging Docker Hub versions
  • invalid argument creating a ruby dev env with docker & fig
  • 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.