Disclaimer - This is a setup that works on my system, using Windows 10 Pro version 19041, WSL2 with docker initialized, and hyper-V enabled. This may not work on other systems but I hope it helps someone. I also cannot guarantee that this won't cause other problems and present this "as is" with no warranties. Use at your own risk.
This cloud-init file may work with multipass on Linux and MacOS also but I haven't tested it.
Multipass allows the use of a cloud-init file to specify how the vm will be configured when it is built, and the main purpose of my use of Multipass is to create docker swarm and Kubernetes clusters locally for educational use, along with trying out different linux things. This means I occasionaly bork an ubuntu vm and can then easily delete it and start over. Updating and installing docker over and over again was not optimal so I automated it.
I also need my machine clean and free of VM's for work (which isn't programming) so I needed a simple way to provision and remove them that worked with everything else I have going on. VirtualBox wasn't cutting it but this works great.
-
Install Multipass on your system. Visit the Multipass homepage and scroll down to the "Install Multipass" header, and click on the installer for windows.
- Note that the Multipass home page has some great instructions to get you started with Ubuntu vm's. Spend some time starting them, naming them, deleting and purging, and getting used to using the tooling.
- Also note that
multipass helpcommand on the command line will only give you the top level help, but you can get additional help with dashes on the help flag in subcommands, such asmultipass launch --help
-
Once installed, test that Multipass installed correctly by opening a terminal and entering the command
multipass version, which should display the currently installed version. -
Copy the docker.yml file from this repo into a directory of your choice. (Feel free to clone this repo if that's your thing, or just copy/paste from my file to yours)
-
Run the Multipass Launch and include the cloud-init file:
multipass launch -n node1 --cloud-init [your-docker.yml-file], and note the file in brackets needs to point to the .yml file you just created.- This should create the new VM, update packages, create a default user named "ubuntu", add the default user to the "docker" group, and install docker. It will also take a few minutes so be patient.
cloud-initfiles can do all sorts of crazy things beside this, but my version is the minimal file I could use to get a docker ready VM. For more on cloud-init see the docs here
-
Run
multipass lsto list active instances and you should see a vm named "node1" in the list. -
Run
multipass shell node1to get an active shell inside the node1 VM and give you a command prompt. The prompt should read "ubuntu@node1:~$" -
At the prompt from step 6, run
docker versionand you should see the version info for both the client and server (daemon) docker installations. If you get them both, you're all set.- If permission is denied to the daemon, try running
sudo rebootand waiting for the instance to start up again, and then usingmultipass shell node1to jump in and verify the docker version again.
- If permission is denied to the daemon, try running
-
When you are done with the VM, there is a 2 part process to remove it.
multipass delete node1will stop the machine and delete it from active use, but it's not actually gone yet. (This is a failsafe against deleting things by accident in case you have something you need in a VM). To fully remove the VM you need to runmultipass purgeafter the delete command and the VM will be permanently deleted.