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?


  • How to restart a single container with docker-compose
  • How can you write a docker daemon that can kick off other docker containers as needed?
  • WSO2 Carbon/API/DSS/ESB - Docker Restart
  • docker stop spark container from exiting
  • Where is the Postgres username/password being created in this Dockerfile?
  • Ansible task timeout max length
  • 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.

  • Connecting to localhost mysql server from inside docker container on macOS
  • Passive replicas with Docker swarm mode
  • How could I ping my docker container from my host
  • how to define HTTP health check in a consul container for a service on the same host?
  • Run docker with volume mapping from another docker container
  • Dockerize application parts of an Axon/JGroups application?
  • 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.