EvilFreelancer / docker-routeros

Mikrotik RouterOS inside Docker container
https://hub.docker.com/r/evilfreelancer/docker-routeros/
MIT License
356 stars 127 forks source link

How to activate KVM #26

Closed maxgamingir closed 6 months ago

maxgamingir commented 6 months ago

the cpu usage is too high how to activate -enable-kvm on QEMU and config docker to access to KVM module?

EvilFreelancer commented 6 months ago

Hi! In Dockerfile you may find an ENTRYPOINT directive:

ENTRYPOINT ["/routeros/entrypoint.sh"]

Content of entrypoint.sh is here.

You can write your own entrypoin.sh script and mount it with help of docker volumes, like that:

version: "3"
services:
  routeros:
    image: evilfreelancer/docker-routeros
    restart: unless-stopped
    cap_add:
      - NET_ADMIN
    devices:
      - /dev/net/tun
      - /dev/kvm
    volumes:
      - ./entrypoin.custom.sh:/routeros/entrypoint.sh

PS. By default KVM should be activated automatically if your CPU supporting this:

CPU_FEATURES=""
KVM_OPTS=""
if [ -e /dev/kvm ]; then
   if grep -q -e vmx -e svm /proc/cpuinfo; then
      echo "Enabling KVM"
      CPU_FEATURES=",kvm=on"
      KVM_OPTS="-machine accel=kvm -enable-kvm"
   fi
fi