How to send http request from Docker to localhost or Virtual Machine

Being new to Docker and VM’s, I have run into a blocker. I have a node app that needs to send a POST request from a Docker container to a Virtual Machine or to my local machine.

I have read through the Docker documentation, but still don’t understand what I need to do in order to accomplish this.

  • Accessing a node.js Hapi server running inside a docker container
  • Spring Boot 1.4.1 SSL trustAnchors exception
  • Dockerfile RUN command taking a lot of disk space
  • How to add jdbc driver to weblogic server running on docker container?
  • Should I have separate containers for Flask, uWSGI, and nginx?
  • Is there a way to share files beween Docker containers that don't exist on the host?
  • So how can I send an http request from my node app running in a Docker Container to my Vagrant Box?

  • Can I run/convert a Docker-Compose project with/to CoreOS rkt?
  • Vagrant Error in Centos
  • how to connect to localhost:9092 from docker container using docker-compose and not using docker bridge
  • How to use Moby to create a custom made container system?
  • How to create a docker image for php and node?
  • Can't remove or stop a container
  • One Solution collect form web for “How to send http request from Docker to localhost or Virtual Machine”

    By default, Docker creates a virtual interface (docker0) in your host machine with IP 172.17.42.1. Each of the container launched will have an IP of the network 172.17.42.1/16, and they will be able to connect to host machine connecting to IP 172.17.42.1.

    If you want to connect a docker container with another service running in a virtual machine running with other provider (e.g.: virtualbox, vmware), the easiest way is forwarding the ports needed by the service to you host machine and then, from your docker container, connecting to IP 172.17.42.1. You should check your virtual machine provider documentation to see details about this. And if you are using libvirt/KVM (or with any other provider), you can use iptables to enable port forwarding.

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