Skip to content

Instantly share code, notes, and snippets.

@laurybueno
Last active November 13, 2022 17:43
Show Gist options
  • Save laurybueno/2e81443a774e77ed9828d0e294c6b3bb to your computer and use it in GitHub Desktop.
Save laurybueno/2e81443a774e77ed9828d0e294c6b3bb to your computer and use it in GitHub Desktop.
Use Lima as a Docker Desktop replacement on MacOS
images:
- location: "https://cloud-images.ubuntu.com/releases/22.04/release-20220902/ubuntu-22.04-server-cloudimg-amd64.img"
arch: "x86_64"
digest: "sha256:c777670007cc5f132417b9e0bc01367ccfc2a989951ffa225bb1952917c3aa81"
- location: "https://cloud-images.ubuntu.com/releases/22.04/release-20220902/ubuntu-22.04-server-cloudimg-arm64.img"
arch: "aarch64"
digest: "sha256:9620f479bd5a6cbf1e805654d41b27f4fc56ef20f916c8331558241734de81ae"
cpus: 8
memory: 8GiB
mountType: "reverse-sshfs"
mounts:
- location: "~"
writable: true
containerd:
system: false
user: false
provision:
- mode: system
script: |
#!/bin/sh
sed -i 's/host.lima.internal.*/host.lima.internal host.docker.internal/' /etc/hosts
- mode: system
script: |
#!/bin/bash
set -eux -o pipefail
command -v docker >/dev/null 2>&1 && exit 0
if [ ! -e /etc/systemd/system/docker.socket.d/override.conf ]; then
mkdir -p /etc/systemd/system/docker.socket.d
# Alternatively we could just add the user to the "docker" group, but that requires restarting the user session
cat <<-EOF >/etc/systemd/system/docker.socket.d/override.conf
[Socket]
SocketUser=${LIMA_CIDATA_USER}
EOF
fi
export DEBIAN_FRONTEND=noninteractive
curl -fsSL https://get.docker.com | sh
probes:
- mode: readiness
description: "Verify if Docker is running"
script: |
#!/bin/bash
set -eux -o pipefail
if ! timeout 30s bash -c "until command -v docker >/dev/null 2>&1; do sleep 3; done"; then
echo >&2 "docker is not installed yet"
exit 1
fi
if ! timeout 30s bash -c "until pgrep dockerd; do sleep 3; done"; then
echo >&2 "dockerd is not running"
exit 1
fi
hint: See "/var/log/cloud-init-output.log". in the guest
- mode: readiness
description: "Enable multiarch runs and builds"
script: |
#!/bin/bash
set -eux -o pipefail
# Enable multi-arch builds and runs
docker run --privileged --rm tonistiigi/binfmt --install all
hostResolver:
hosts:
host.docker.internal: host.lima.internal
portForwards:
- guestSocket: "/var/run/docker.sock"
hostSocket: "{{.Dir}}/sock/docker.sock"
message: |
To run `docker` on the host (assumes docker-cli is installed), run the following commands:
------
docker context create lima-{{.Name}} --docker "host=unix://{{.Dir}}/sock/docker.sock"
docker context use lima-{{.Name}}
docker run hello-world
------
Or:
------
export DOCKER_HOST='unix://{{.Dir}}/sock/docker.sock'
------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment