├── create-and-init.sh ├── cloud-init.yml └── README.md /create-and-init.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -xe 3 | 4 | MEM=2048M 5 | CPUS=2 6 | DISK=20G 7 | 8 | echo "Creating and launching instance" 9 | multipass launch --name primary -c $CPUS -m $MEM -d $DISK --cloud-init cloud-init.yml 10 | 11 | echo "Mounting $HOME into remote instance: primary" 12 | multipass mount ${HOME} primary:/Users/${USER} 13 | 14 | PRIMARY_INSTANCE=$(multipass info primary | grep IPv4 | awk '{split($0,a," "); print a[2]}') 15 | 16 | echo "Success! in your bash profile add this:" 17 | echo "export DOCKER_HOST=tcp://$PRIMARY_INSTANCE:2375" 18 | -------------------------------------------------------------------------------- /cloud-init.yml: -------------------------------------------------------------------------------- 1 | #cloud-config 2 | 3 | package_update: true 4 | package_upgrade: true 5 | package_reboot_if_required: true 6 | 7 | manage-resolv-conf: true 8 | resolv_conf: 9 | nameservers: 10 | - "8.8.8.8" 11 | - "8.8.4.4" 12 | 13 | apt: 14 | sources: 15 | docker.list: 16 | source: deb https://download.docker.com/linux/ubuntu $RELEASE stable 17 | keyid: 9DC858229FC7DD38854AE2D88D81803C0EBFCD88 18 | 19 | packages: 20 | - apt-transport-https 21 | - ca-certificates 22 | - curl 23 | - gnupg-agent 24 | - software-properties-common 25 | - docker-ce 26 | - docker-ce-cli 27 | - containerd.io 28 | 29 | write_files: 30 | - path: /etc/systemd/system/docker.service.d/override.conf 31 | content: | 32 | # Disable flags to dockerd, all settings are done in /etc/docker/daemon.json 33 | [Service] 34 | ExecStart= 35 | ExecStart=/usr/bin/dockerd 36 | - path: /etc/sysctl.d/enabled_ipv4_forwarding.conf 37 | content: | 38 | net.ipv4.conf.all.forwarding=1 39 | - path: /etc/docker/daemon.json 40 | content: | 41 | { 42 | "dns": [ 43 | "8.8.8.8", 44 | "8.8.4.4" 45 | ], 46 | "hosts": ["tcp://0.0.0.0:2375", "unix:///var/run/docker.sock"] 47 | } 48 | runcmd: 49 | - systemctl start docker 50 | - systemctl enable docker 51 | 52 | groups: 53 | - docker 54 | 55 | # Add default auto created user to docker group 56 | system_info: 57 | default_user: 58 | groups: [docker] 59 | 60 | final_message: "The system is finally up, after $UPTIME seconds" 61 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Docker with multipass on macOS 2 | 3 | ## Prerequisites 4 | 5 | ```bash 6 | $ brew install multipass 7 | ``` 8 | 9 | # Usage 10 | 11 | This will create and launch an instance called primary. Multipass by default will mount your `$HOME` directory if the instance is named `primary`. 12 | 13 | ```bash 14 | $ ./create-and-init.sh 15 | + MEM=2048M 16 | + CPUS=2 17 | + DISK=20G 18 | + echo 'Creating and launching instance' 19 | Creating and launching instance 20 | + multipass launch --name primary -c 2 -m 2048M -d 20G --cloud-init cloud-init.yml 21 | Launched: primary 22 | Mounted '/Users/chrisgoffinet' into 'primary:Home' 23 | + echo 'Mounting /Users/chrisgoffinet into remote instance: primary' 24 | Mounting /Users/chrisgoffinet into remote instance: primary 25 | + multipass mount /Users/chrisgoffinet primary:/Users/chrisgoffinet 26 | ++ multipass info primary 27 | ++ grep IPv4 28 | ++ awk '{split($0,a," "); print a[2]}' 29 | + PRIMARY_INSTANCE=192.168.64.13 30 | + echo 'Success! in your bash profile add this:' 31 | Success! in your bash profile add this: 32 | + echo 'export DOCKER_HOST=tcp://192.168.64.13:2375' 33 | export DOCKER_HOST=tcp://192.168.64.13:2375 34 | ``` 35 | 36 | Now that your `DOCKER_HOST` is pointed to your `primary` instance running commands like you normally do should just work as expected. 37 | 38 | ```bash 39 | $ docker pull busybox 40 | Using default tag: latest 41 | latest: Pulling from library/busybox 42 | 8ba530ca112c: Pull complete 43 | Digest: sha256:15e927f78df2cc772b70713543d6b651e3cd8370abf86b2ea4644a9fba21107f 44 | Status: Downloaded newer image for busybox:latest 45 | docker.io/library/busybox:latest 46 | $ docker images 47 | REPOSITORY TAG IMAGE ID CREATED SIZE 48 | busybox latest cc54699a1d7e 8 days ago 1.41MB 49 | $ echo 'test 123' > test.txt 50 | $ docker run --rm -it -v $PWD/test.txt:/test.txt busybox sh 51 | / # cat /test.txt 52 | test 123 53 | / # 54 | ``` 55 | 56 | ## How do I configure disk, memory, and cpu? 57 | 58 | You can configure the variables in the `create-and-init.sh` script. 59 | 60 | ``` 61 | MEM=2048M 62 | CPUS=2 63 | DISK=20G 64 | ``` 65 | 66 | ## Can this replace Docker Desktop? 67 | 68 | Yes, on macOS you can install `docker` using `brew`, so no need to go and install `Docker Desktop`. 69 | 70 | ```bash 71 | $ brew install docker 72 | ``` 73 | 74 | ## How do I shell into the instance? 75 | 76 | ```bash 77 | $ multipass shell 78 | ``` 79 | --------------------------------------------------------------------------------