Skip to content

Commit

Permalink
Add docker and podman client wrapper scripts
Browse files Browse the repository at this point in the history
Install the extra client wrappers

But don't set up any alias for "docker" or "podman", by default.
They would conflict with the regular client (binary) programs.

Use environment variables

This means it will work with multiple instances if needed.
Instead of hardcoding just one context/connection, "lima".

Exit if instance does not exist

Signed-off-by: Anders F Björklund <[email protected]>
  • Loading branch information
afbjorklund committed May 12, 2022
1 parent 234a65c commit 6baccd7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ binaries: clean \
_output/bin/lima \
_output/bin/limactl \
_output/bin/nerdctl.lima \
_output/bin/docker.lima \
_output/bin/podman.lima \
_output/share/lima/lima-guestagent.Linux-x86_64 \
_output/share/lima/lima-guestagent.Linux-aarch64 \
_output/share/lima/lima-guestagent.Linux-riscv64
Expand All @@ -40,6 +42,14 @@ _output/bin/nerdctl.lima:
mkdir -p _output/bin
cp -a ./cmd/nerdctl.lima $@

_output/bin/docker.lima: ./cmd/docker.lima
@mkdir -p _output/bin
cp -a $^ $@

_output/bin/podman.lima: ./cmd/podman.lima
@mkdir -p _output/bin
cp -a $^ $@

.PHONY: _output/bin/limactl
_output/bin/limactl:
# The hostagent must be compiled with CGO_ENABLED=1 so that net.LookupIP() in the DNS server
Expand Down
18 changes: 18 additions & 0 deletions cmd/docker.lima
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh
set -eu
: "${LIMA_INSTANCE:=docker}"
: "${DOCKER:=docker}"

if [ "$(limactl ls -q "$LIMA_INSTANCE" 2>/dev/null)" != "$LIMA_INSTANCE" ]; then
echo "instance \"$LIMA_INSTANCE\" does not exist, run \`limactl start --name=$LIMA_INSTANCE template://docker\` to create a new instance" >&2
exit 1
fi
DOCKER=$(command -v "$DOCKER" || true)
if [ -n "$DOCKER" ]; then
DOCKER_HOST=$(limactl list "$LIMA_INSTANCE" --format 'unix://{{.Dir}}/sock/docker.sock')
export DOCKER_HOST
exec "$DOCKER" "$@"
else
export LIMA_INSTANCE
exec lima docker "$@"
fi
18 changes: 18 additions & 0 deletions cmd/podman.lima
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh
set -eu
: "${LIMA_INSTANCE:=podman}"
: "${PODMAN:=podman}"

if [ "$(limactl ls -q "$LIMA_INSTANCE" 2>/dev/null)" != "$LIMA_INSTANCE" ]; then
echo "instance \"$LIMA_INSTANCE\" does not exist, run \`limactl start --name=$LIMA_INSTANCE template://podman\` to create a new instance" >&2
exit 1
fi
PODMAN=$(command -v "$PODMAN" || true)
if [ -n "$PODMAN" ]; then
CONTAINER_HOST=$(limactl list "$LIMA_INSTANCE" --format 'unix://{{.Dir}}/sock/podman.sock')
export CONTAINER_HOST
exec "$PODMAN" --remote "$@"
else
export LIMA_INSTANCE
exec lima podman "$@"
fi

0 comments on commit 6baccd7

Please sign in to comment.