Show Menu
Cheatography

Multipass CLI 2022, Ubuntu VMs on demand on any OS Cheat Sheet by

Get an instant Ubuntu VM with a single command. Multipass can launch and run virtual machines and configure them with cloud-init like a public cloud.

Create Instances

multipass launch
Creates an instance using a random name
multipass info <in­sta­nce>
Get info about an instance
multipass find
find out what images are available
multipass launch <im­age>
launch an instance using the specified image
multipass launch <im­age> [--nam­e|-n] <in­sta­nce>
launch an instance and name it
multipass launch [--cpu­s|-c] 4 [--dis­k,-d] 20G [--mem,-m] 8G
Create an instance with custom CPU number, disk, and RAM
multipass launch <im­age> [--nam­e,-n] primary
An instance can obtain the primary status at creation time if its name is primary. A primary instance is the default argument for several commands, such as shell , start , stop , restart , and suspend and also automa­tically mounts our $HOME directory in the instance.
multipass launch --network en0 --network name=b­rid­ge0­,mo­de=­manual
The --network option can be given multiple times, each one requesting an additional network interface (beyond the default one, which is always present, used to reach the outside world and used by multipass to commun­icate with the instance).

--network takes at most 3 <ke­y>=­<va­lue­>:
name — the only required value, it identifies the network,
mode that is either manual or auto (try to auto join the net),
mac to specify a mac address for the NIC

NIC: network interface controller

Create an instance with a custom DNS

multipass launch --clou­d-init system­d-r­eso­lve­d.yaml
Creates an instance with a custom DNS
after the instance booted use the netplan.io approach
In some scenarios the default of using the system­-pr­ovided DNS will not be suffic­ient.

system­d-r­eso­lve­d.yaml cloud-init snippet:

#cloud­-config
bootcmd:
- printf "­[Re­sol­ve]­\nD­NS=­8.8.8.8­" > /etc/s­yst­emd­/re­sol­ved.conf
- [syste­mctl, restart, system­d-r­eso­lved]

8.8.8.8 is a Google DNS

Remove or delete an instance

multipass delete <in­sta­nce>
Move an instance to the ‘recycle bin’
multipass delete --all
Move all instances to the ‘recycle bin’
multipass recover <in­sta­nce>
Recover an instance put to the ‘recycle bin’
multipass delete --purge <in­sta­nce>
Perman­ently delete an instance
multipass purge
Empty the ‘recycle bin’

Running a container with the Docker workflow

multipass launch docker
Creates a virtual machine running the latest version of Ubuntu, with Docker and Portainer installed.
multipass exec docker docker
Executes Docker in the instance
multipass alias docker­:docker
Alias the docker command to our host command line. This will let us use the docker command as if Docker were running directly on our host machin­e.This command will return instru­ctions showing how to add the new alias to our path. Simply copy and paste the command shown. It will likely be of this form: PATH="$­PAT­H:/­hom­e/<­use­r>/­sna­p/m­ult­ipa­ss/­com­mon­/bi­n"
docker run hello-­world
Works only if the alias is created.
multipass list
Shows the IP addresses associated with the created Ddocker VM. The Portainer IP should start with a 10.
Shows the Portainer web interface.
Portainer config
1) Set username and password
2) Select local docker env opt. and click connect
3) Click on the newly created “Local” enviro­nment to manage the Docker instance on our local VM.
see https:­//m­ult­ipa­ss.r­un­/do­cs/­doc­ker­-tu­torial
 

Install

brew install bash-c­omp­letion
install bash completion if not already installed
brew install --cask multipass
--cask option may be omitted
brew uninstall multipass
uninstall multipass
brew uninstall --zap multipass
uninstall multipass and data
multipass version
to check the install and get the version

Modify an instance

multipass set client.pr­ima­ry-­nam­e=<­ins­tance name>
Grant a regular instance the primary status
multipass set [local.<i­nst­anc­e>.(­cp­us|­dis­k|m­emory)]
Change CPU RAM DISK

Use an Instance

multipass shell <in­sta­nce>
Open a shell prompt inside an instance
multipass exec <in­sta­nce> -- <cm­d>
Execute a command inside an instance
multipass start|­sus­pen­d|stop <in­sta­nce­>[ <in­sta­nce­>]
Start, suspend or stop instances
multipass start|­sus­pen­d|stop -all
Start, suspend or stop all instances

Aliases on Instances

multipass alias <in­sta­nce­>:<­cmd> <al­ias>
defines an alias executed from the host, into the instance. ex: multipass alias proxy:ls lsproxy
multipass alias <in­sta­nce­>:<­cmd> <al­ias> --no-m­ap-­wor­kin­g-d­ire­ctory
Do not change the working directory on the instance to the mounted directory (in case the host folder on which executing an alias is mounted on the instance)
multipass aliases
list defined aliases and their instances
multipass <al­ias>
execute an alias
multipass unalias <al­ias­>[ <al­ias­>]
remove aliases
multipass unalias --all
remove all aliases
Add the multipass bin folder to the path to use <al­ias> instead of multipass <al­ias­>.
Arguments are also supported

nano ~/.bashrc #linux
nano ~/.zshhrc #mac
PATH="$­PAT­H:/­hom­e/u­ser­/sn­ap/­mul­tip­ass­/co­mmo­n/b­in"

Share data with an instance using "­mou­nt"

multipass mount $HOME <in­sta­nce>
/home/me will be available inside the instance.
multipass mount $HOME <in­sta­nce­>:<­/in­sta­nce­/pa­th>
Specifies the path inside the instance in which to mount the local path
multipass launch --mount </l­oca­l/p­ath­>:m­ult­ipass launch --mount /some/­loc­al/­pat­h:/­ins­tan­ce/path
Specifies mount on launch
multipass umount <in­sta­nce>
Unmount all volumes from an instance
multipass umount <in­sta­nce­>:<­/in­sta­nce­/pa­th>
Unmount a specific volume from an instance
The recomm­ended way to share data between your host and an instance with Multipass is the mount command

Share data with an instance using "­tra­nsf­er"

multipass transfer <in­sta­nce­>:<­/in­sta­nce­/pa­th/­fil­e1> <in­sta­nce­>:<­/in­sta­nce­/pa­th/­fil­e2> </h­ost­/pa­th>
Copy 2 files from the instance to the specified host path
multipass transfer <in­sta­nce­>:<­/in­sta­nce­/pa­th> </h­ost­/pa­th/­fil­e1> </h­ost­/pa­th/­fil­e2>­<in­sta­nce­>:<­/in­sta­nce­/pa­th>
Copy 2 files from the host path to the specified instance path
use transfer to just copy files around. If a file is inside an instance, prefix its path with <in­stance name>:.

Miscel­laneous

multipass exec primary -- bash -c 'echo "­Pas­SwO­rD" | docker secret create secret­-pass -'
create a docker secret in the primary node without storing it
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          More Cheat Sheets by Boulard

          Photoshop 2021 Cheat Sheet
          Illustrator 2021 Cheat Sheet Cheat Sheet
          Docker & Swarm 2022 Cheat Sheet