Skip to content

Virt-Manager and Docker: Networking Conflicts Explained

How to fix network bridge conflicts when running Virt-Manager and Docker on the same machine.

Running Virt-Manager (which utilizes libvirt and KVM) and Docker on the same Linux host frequently results in severe networking conflicts. While it is technically possible to force them to coexist, the default behavior of both services makes them fundamentally incompatible on a shared host network.

The Root Cause: Iptables and Packet Routing

The core issue stems from how both Docker and libvirt handle Linux networking and firewall rules (iptables or nftables).

  1. Docker's Aggressive Network Management: When the Docker daemon starts, it assumes total control over the system's firewall routing to manage container networking. It creates its own bridge interfaces (like docker0) and automatically modifies the iptables rules. Specifically, Docker alters the FORWARD chain policy to DROP to isolate container traffic for security.
  2. Libvirt's Bridge Requirements: Virt-Manager/libvirt relies on its own virtual network bridge (typically virbr0) to provide NAT (Network Address Translation) and DHCP services to virtual machines. It requires specific FORWARD and POSTROUTING rules to allow packets to travel from the VMs to the external network and back.
  3. The Conflict: When Docker sets the default FORWARD policy to DROP, it indiscriminately blocks the forwarded traffic generated by libvirt's virtual machines. The result is that your KVM virtual machines will suddenly lose internet access, or the host will be unable to communicate with the VMs over the local network.

Because Docker dynamically rewrites these iptables rules upon every restart or container deployment, manually adding libvirt rules is not a permanent fix; Docker will continually overwrite or bypass them.

Complete Purge of Docker and Docker Compose (Multi-Distribution)

To restore standard networking for Virt-Manager, Docker and all its associated networking rules, dependencies, and configuration files must be completely removed from the host.

The following command block provides the full, updated script. It is now designed to automatically detect your distribution's package manager (apt for Debian/Ubuntu, dnf for Fedora/RHEL, or pacman for Arch Linux) and execute the appropriate uninstallation and orphaned-dependency removal commands automatically.

Package Manager Explanations

  • APT (Debian/Ubuntu): Uses purge to remove packages and their configuration files, followed by autoremove --purge to strip out orphaned dependencies left behind.
  • DNF (Fedora/RHEL): Uses remove targeting a wide array of legacy and modern Docker package names to ensure a clean sweep, followed by autoremove to clear unused dependencies.
  • Pacman (Arch Linux): Uses the -Rns flag. R removes the packages, n removes global configuration files (acting like purge), and s removes recursive dependencies that are no longer needed (acting like autoremove). This completes both steps in one command.
#!/bin/bash

# 1. Stop all running Docker and Containerd services and sockets
sudo systemctl stop docker.service
sudo systemctl stop docker.socket
sudo systemctl stop containerd.service

# 2 & 3. Detect Package Manager, Uninstall Docker Packages, and Remove Orphans
if command -v apt-get &> /dev/null; then
    echo "Detected APT package manager (Debian/Ubuntu based)."
    sudo apt-get purge -y docker-engine docker docker.io docker-ce docker-ce-cli docker-ce-rootless-extras docker-buildx-plugin docker-compose-plugin docker-compose containerd.io runc
    sudo apt-get autoremove -y --purge

elif command -v dnf &> /dev/null; then
    echo "Detected DNF package manager (Fedora/RHEL/CentOS based)."
    sudo dnf remove -y docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine docker-ce docker-ce-cli docker-ce-rootless-extras docker-buildx-plugin docker-compose-plugin docker-compose containerd.io runc
    sudo dnf autoremove -y

elif command -v pacman &> /dev/null; then
    echo "Detected Pacman package manager (Arch Linux based)."
    # -Rns removes target packages, configuration files (-n), and unneeded dependencies (-s)
    sudo pacman -Rns --noconfirm docker docker-compose containerd runc

else
    echo "Error: Supported package manager (apt, dnf, pacman) not found."
    echo "Please remove Docker packages manually, then proceed with the rest of the script."
fi

# 4. Delete all Docker and Containerd directories, configuration files, and container data
# WARNING: This permanently deletes all your containers, images, and docker volumes.
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
sudo rm -rf /etc/docker
sudo rm -rf /etc/apparmor.d/docker
sudo rm -rf /var/run/docker.sock
sudo rm -rf /usr/local/bin/docker-compose
sudo rm -rf ~/.docker

# 5. Remove the Docker user group
sudo groupdel docker

# 6. Restart the libvirt daemon to allow it to safely rebuild its network rules
sudo systemctl restart libvirtd