Skip to content

Instantly share code, notes, and snippets.

@svanellewee
Last active November 1, 2022 22:29
Show Gist options
  • Save svanellewee/ed709745726a58f53c7969bcb887f78f to your computer and use it in GitHub Desktop.
Save svanellewee/ed709745726a58f53c7969bcb887f78f to your computer and use it in GitHub Desktop.
start multipass docker.
#!/usr/bin/env bash
export DOCKER_HOST=ssh://ubuntu@docker.local
export DOCKER_HOST=tcp://docker.local
multipass set client.primary-name=docker
function start-docker() {
local SSH_KEY="id_$RANDOM"
local PUBLIC_SSH_KEY="${SSH_KEY}.pub"
ssh-keygen -b 2048 -t rsa -f "$SSH_KEY" -P ""
ssh-add "${SSH_KEY}"
cat <<-EOF | tee /tmp/user-conf.yml
---
users:
- name: ubuntu
sudo: ALL=(ALL) NOPASSWD:ALL
ssh-authorized-keys:
- $(cat ${PUBLIC_SSH_KEY})
package_update: true
packages:
- docker
- avahi-daemon
- apt-transport-https
- ca-certificates
- curl
- gnupg
- lsb-release
write_files: # Allows us to mount docker directly without ssh magics..
- path: /etc/systemd/system/docker.service.d/docker.conf
content:
|
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd
- path: /etc/docker/daemon.json
content:
|
{
"insecure-registries": [],
"hosts": ["unix:///var/run/docker.sock","tcp://0.0.0.0:2375"],
"features": { "buildkit" : true }
}
runcmd:
- sudo curl -fsSL https://get.docker.com | sudo bash
- sudo systemctl enable docker
- sudo systemctl enable -s HUP ssh
- sudo groupadd docker
- sudo usermod -aG docker ubuntu
EOF
multipass launch -c 2 -m 2G -d 40G -n docker 20.04 --cloud-init /tmp/user-conf.yml
echo "done"
}
@svanellewee
Copy link
Author

The docker.conf and daemon.json overrides the original ExecStart Value so that I can specify the hosts myself in a simpler way in json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment