Skip to content

Instantly share code, notes, and snippets.

@craig-m-unsw
Forked from avoidik/README.md
Created May 31, 2024 08:06
Show Gist options
  • Save craig-m-unsw/026edd2f1def8b038981267bb054c19f to your computer and use it in GitHub Desktop.
Save craig-m-unsw/026edd2f1def8b038981267bb054c19f to your computer and use it in GitHub Desktop.
Plain simple alternative to Docker Desktop

Multipass

It works both with VirtualBox and Hyper-V on Windows, it also support MacOS including M1

Install

Configure virtualization driver

If you want VirtualBox (works on Linux, Windows, and MacOS)

multipass set local.driver=virtualbox

If you want Hyper-V

multipass set local.driver=hyperv

On MacOS M1 you probably would want to use Hyperkit

multipass set local.driver=hyperkit

Launch docker in a VM

multipass launch docker

You can set disk, CPU, RAM limits, and name

multipass launch docker --cpus 2 --disk 2G --mem 2G --name docker

Create alias (it may ask to update PATH environment variable)

multipass alias docker:docker

View all aliases

multipass aliases

Connect to shell

multipass shell docker

Remove alias

multipass unalias docker

List and terminate VMs

multipass list
multipass info
multipass delete docker

Purge deleted VM

multipass purge

Combine purge and delete in one command

multipass delete -p docker

List all available options

multipass --help

Host-only network with VirtualBox

Change VM config, add host-only adapter

multipass stop docker
psexec64 -nobanner -s "%VBOX_MSI_INSTALL_PATH%\vboxmanage" showvminfo docker
psexec64 -nobanner -s "%VBOX_MSI_INSTALL_PATH%\vboxmanage" modifyvm docker --nic2 hostonly --hostonlyadapter2 "VirtualBox Host-Only Ethernet Adapter"
multipass start docker

Set netplan configuration

multipass shell docker
cat <<EOF | sudo tee /etc/netplan/60-host-only.yaml > /dev/null
network:
  ethernets:
    enp0s8:
      optional: yes
      dhcp4: yes
      dhcp4-overrides:
         route-metric: 110
      match:
         macaddress: $(cat /sys/class/net/enp0s8/address)
      set-name: enp0s8
      dhcp6: no
  version: 2
EOF
sudo netplan apply
ip addr show enp0s8

What is route-metric: 110? We don't want to put our new network interface route before the default route with metric 100.

Manage VMs in VirtualBox UI

psexec64 -nobanner -i -s "%VBOX_MSI_INSTALL_PATH%\virtualbox"

PsExec can be downloaded from live.sysinternals.com

For Windows there is an alternative to psexec called gsudo

gsudo -s "%VBOX_MSI_INSTALL_PATH%\virtualbox"
gsudo -s "%VBOX_MSI_INSTALL_PATH%\vboxmanage" showvminfo docker --machinereadable | find /I "nic"

Cloud-init

cat > cloud-init.yaml <<'EOF'
write_files:
- path: /etc/netplan/60-host-only.yaml
  permissions: '0644'
  content: |
    network:
      ethernets:
        IFACE_NAME:
          optional: yes
          dhcp4: yes
          dhcp4-overrides:
            route-metric: 110
          set-name: IFACE_NAME
          dhcp6: no
      version: 2

runcmd:
- 'sed -i "s/IFACE_NAME/enp0s8/g" /etc/netplan/60-host-only.yaml'
- 'netplan generate'
- 'netplan apply'
EOF
multipass launch docker --cloud-init cloud-init.yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment