Skip to content

Instantly share code, notes, and snippets.

@thomet
Last active August 19, 2022 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomet/d74cc9c60a75c1ef747d63893463694e to your computer and use it in GitHub Desktop.
Save thomet/d74cc9c60a75c1ef747d63893463694e to your computer and use it in GitHub Desktop.
Docker for Mac without DockerDesktop

Mac Docker Setup

/bin/bash -c "$(curl -fsSL https://gist.githubusercontent.com/thomet/d74cc9c60a75c1ef747d63893463694e/raw/multipass-mac-docker-setup.sh)"

Note

Make sure you give multipass.app full disk access

#cloud-config
package_update: true
package_upgrade: true
package_reboot_if_required: true
bootcmd:
- rm -rf /etc/resolv.conf
- echo 'nameserver 1.1.1.1' > /etc/resolv.conf
apt:
sources:
docker.list:
source: deb https://download.docker.com/linux/ubuntu $RELEASE stable
keyid: 9DC858229FC7DD38854AE2D88D81803C0EBFCD88
golang-ppa.list:
source: deb http://ppa.launchpad.net/longsleep/golang-backports/ubuntu $RELEASE main
keyid: F6BC817356A3D45E
packages:
- apt-transport-https
- ca-certificates
- curl
- gnupg-agent
- software-properties-common
- docker-ce
- docker-ce-cli
- containerd.io
- docker-compose
- golang
- unzip
write_files:
- path: /etc/systemd/system/docker.service.d/override.conf
content: |
# Disable flags to dockerd, all settings are done in /etc/docker/daemon.json
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd
- path: /etc/sysctl.d/enabled_ipv4_forwarding.conf
content: |
net.ipv4.conf.all.forwarding=1
- path: /etc/sysctl.d/elasticsearch.conf
content: |
vm.max_map_count=262144
- path: /etc/docker/daemon.json
content: |
{
"dns": [
"1.1.1.1"
],
"hosts": ["tcp://0.0.0.0:2375", "unix:///var/run/docker.sock"]
}
- content: '{"credsStore": "ecr-login"}'
owner: ubuntu:ubuntu
path: /home/ubuntu/.docker/config.json
defer: true
- content: 'export PATH="$PATH:/home/ubuntu/go/bin"'
owner: ubuntu:ubuntu
path: /home/ubuntu/.bashrc
defer: true
append: true
runcmd:
- su ubuntu -c "go install github.com/awslabs/amazon-ecr-credential-helper/ecr-login/cli/docker-credential-ecr-login@latest"
- curl https://awscli.amazonaws.com/awscli-exe-linux-`arch`.zip -o awscliv2.zip
- unzip awscliv2.zip
- ./aws/install
- rm awscliv2.zip
- chown ubuntu:ubuntu /home/ubuntu/.docker
- systemctl start docker
- systemctl enable docker
groups:
- docker
system_info:
default_user:
groups: [docker]
swap:
filename: /swap.img
size: "auto"
maxsize: 1572864
#!/usr/bin/env bash
set -e
# Install Homebrew if not installed
if ! command -v brew >/dev/null; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
fi
# Install multipass if not installed
if ! brew list -1 | grep -Fx "multipass" >/dev/null; then
brew install multipass
fi
# Install docker if not installed
if ! brew list -1 | grep -Fx "docker" >/dev/null; then
brew install docker
fi
HOST_CPU_COUNT=`sysctl -n hw.ncpu`
HOST_MEM=`sysctl -n hw.memsize`
VM_CORE_DEFAULT=`echo $HOST_CPU_COUNT/2 | bc`
VM_MEM_DEFAULT=`echo $HOST_MEM/ 1024 / 1024 / 1024 / 2 | bc`
VM_DISK_SIZE_DEFAULT=100
read -p "How many cpus should be assigned to the vm [${VM_CORE_DEFAULT}]: " vm_cpu_core
vm_cpu_core=${vm_cpu_core:-$VM_CORE_DEFAULT}
read -p "How many gigabyte MEM should be assigned to the vm [${VM_MEM_DEFAULT}]: " vm_mem_size
vm_mem_size=${vm_mem_size:-$VM_MEM_DEFAULT}
read -p "How many gigabyte diskspace should be assigned to the vm [${VM_DISK_SIZE_DEFAULT}]: " vm_disk_size
vm_disk_size=${vm_disk_size:-$VM_DISK_SIZE_DEFAULT}
# Create vm with docker (use 50% CPU and RAM by default)
multipass launch \
-c ${vm_cpu_core} \
-m ${vm_mem_size}G \
-d ${vm_disk_size}G \
-n docker-vm \
--mount /tmp:/tmp \
--mount /Users:/Users \
--mount /Volumes:/Volumes \
--mount /private:/private \
--mount /var/folders:/var/folders \
--cloud-init https://gist.githubusercontent.com/thomet/d74cc9c60a75c1ef747d63893463694e/raw/cloud-config.yml
PRIMARY_INSTANCE=$(multipass info docker-vm | grep IPv4 | awk '{split($0,a," "); print a[2]}')
echo "Success! in your bash profile add this:"
echo "export DOCKER_HOST=tcp://$PRIMARY_INSTANCE:2375"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment