| 1 | #!/bin/sh |
| 2 | set -eu |
| 3 | |
| 4 | # Environment Variables |
| 5 | # LIMA_INSTANCE: Specifies the name of the Lima instance to use. Default is "docker". |
| 6 | |
| 7 | : "${LIMA_INSTANCE:=docker}" |
| 8 | : "${DOCKER:=docker}" |
| 9 | |
| 10 | if [ "$(limactl ls -q "$LIMA_INSTANCE" 2>/dev/null)" != "$LIMA_INSTANCE" ]; then |
| 11 | echo "instance \"$LIMA_INSTANCE\" does not exist, run \`limactl create --name=$LIMA_INSTANCE template:docker\` to create a new instance" >&2 |
| 12 | exit 1 |
| 13 | elif [ "$(limactl ls -f '{{ .Status }}' "$LIMA_INSTANCE" 2>/dev/null)" != "Running" ]; then |
| 14 | echo "instance \"$LIMA_INSTANCE\" is not running, run \`limactl start $LIMA_INSTANCE\` to start the existing instance" >&2 |
| 15 | exit 1 |
| 16 | fi |
| 17 | DOCKER=$(command -v "$DOCKER" || true) |
| 18 | if [ -n "$DOCKER" ]; then |
| 19 | DOCKER_HOST=$(limactl list "$LIMA_INSTANCE" --format 'unix://{{.Dir}}/sock/docker.sock') |
| 20 | export DOCKER_HOST |
| 21 | exec "$DOCKER" "$@" |
| 22 | else |
| 23 | export LIMA_INSTANCE |
| 24 | exec lima docker "$@" |
| 25 | fi |