Docker Community Forums

Share and learn in the Docker community.

Connecting containers to local machine or VM on hyper-v

Hi guys! I’m a newbie in docker and i need some help in my project.
I have three containers created on the same network in bridge mode. They can talk between them.
I have too a VM hosted at hyper-v running CentOS 7.
I need that VM can be communicate with theses containers.

How is made this configuration?

I already tried put network vm on the same network of containers, but do not resolves.

If someone can be help me, i thank so much.

Publish the services you need from the containers to ports of your Docker host, then connect from the VM to ip_of_docker_host:some_port.

Hi bro! Thanks for your answer.
Excuse me my ignorance but, how i must do it?
insert in docker-compose file, execute in docker bash?..

Containers are not VMs, but services, or we could say: containers add services to your host.
Everything you do in a compose file you can do on the command line, just with docker-compose it’s more convenient. For example with

docker container run --rm -p 8080:80 httpd

you attach an Apache web server to your host at port 8080. You can write a simple compose file

---
version: "2.4"
services:
  one:
    image: httpd
    ports:
      - "8080:80"
  two:
    image: nginx
    ports:
      - "8081:80"

that will add an Apache server at port 8080 and an Nginx server at port 8081. If you are on the same machine you can call them with http://localhost:8080 and http://localhost:8081. If you want to access them from your VM you have to replace localhost with the IP address of your Docker host.

I maked something like this. In my compose file…i configured a bridge network to the containers. So it possiblity they talk between they. After this, i configured the routes from iptables to my VM where is running my tomcat and success.
Create a bridge network to my containers it was very important. Thank you bro!

This is a somewhat different approach. Containers started with the same compose file always have access to each other with the service name as URL, a network is created automatically by docker-compose. If you attach the external VM to this network you probably expose too many internals to the outside.