I have one host with docker and KVM, and I would like to connect from a docker container to a KVM Virtual Machine.

I was able to connect from KVM Virtual Machine to docker container, but not the other way round.

I followed this approach and when I try to ssh to the KVM from the docker container I get No route to host.

I tried with and without "iptables": false setting on /etc/docker/daemon.json file.

I guess is something to do with iptables at host level.

Any help will be appreciated.


Edit 1

I can confirm:

  • It is possible to connect docker container to KVM VM
  • The root cause of my issue was stale iptables rules

To resolve the issue:

  1. Backup all the iptables rules
sudo iptables-save > your-current-iptables.rules
sudo iptables-legacy-save > your-current-iptables-legacy.rules

If second command fails you can ignore it

  1. Stop services
sudo service docker stop
sudo service libvirtd stop
  1. Edit the docker configuration file

3.1. Backup the file

sudo cp /etc/docker/daemon.json /etc/docker/daemon.json.bak

3.2. Edit the file

sudo vim /etc/docker/daemon.json

And make sure below lines are present:

  "bridge": "virbr1",
  "iptables": false,

Make sure libvirt1 matches your KVM bridge

  1. Start services
sudo service libvirtd start
sudo service docker start
  1. Test connectivity

    • Make sure that your docker container is connected to default network (bridge) by default

Edit 2

Even without the "bridge": "virbr1" setting everything works as expected, so:

  • Both services, libvirt and docker adds iptables rules
  • Both services provision Virtual Machines and containers in the same subnet ( in my case
  • There are connectivity across "machines" in this network (docker container can SSH to the Virtual Machine, and Virtual Machine can ping the docker container)
  • Both "machines" has DNS and internet connectivity (ping

Edit 3

Sorry, no idea how can I:

  • Add edits 2 and 3 as an answer of my own question (I guess a comment is not an answer)
  • Mark my own answer as the correct one, in order to mark this question as resolved


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.