Rancher Desktop

Use Rancher Desktop with LocalStack

Introduction

Rancher Desktop is a desktop application that provides a Kubernetes cluster on your local machine. Rancher Desktop allows you to run Docker containers and Kubernetes clusters without relying on remote or cloud-based systems. It utilizes containerd and dockerd, enabling users to easily switch between container runtimes.

By default, the LocalStack CLI launches the LocalStack runtime inside a Docker container. However, if Docker is not available on your system, you can use Rancher Desktop as a popular alternative to run LocalStack.

Getting started

To run LocalStack using Rancher Desktop, simply aliasing Docker commands to Rancher Desktop’s dockerd service may not be sufficient for these reasons:

  1. LocalStack depends on docker-py, which needs to connect to /var/run/docker.sock.
  2. Lambda services in LocalStack require the Docker socket at /var/run/docker.sock to be mounted into the container.

Depending on your operating system, you may need to make additional configurations to ensure LocalStack runs smoothly with Rancher Desktop.

These setups enable LocalStack to run smoothly with Rancher Desktop across various operating systems, ensuring compatibility with Docker-based workflows.

Linux/macOS

Rancher Desktop with dockerd

The simplest way to run LocalStack using Rancher Desktop involves making sure that Rancher Desktop’s dockerd is active and properly configured. Rancher Desktop typically places its Docker socket file somewhere under your user directory, such as ~/.rancher-desktop. LocalStack, however, expects the Docker socket to be at /var/run/docker.sock. In this scenario, you need to create a symlink from the Rancher Desktop socket to the expected location.

Start Rancher Desktop and verify it is set to use the Docker runtime. Link the Docker socket with the following command:

# 1. Make sure there is no existing socket at /var/run/docker.sock
sudo rm -f /var/run/docker.sock

# 2. Adjust the path if your Rancher Desktop socket is in a different location
$ sudo ln -s /var/run/rancher-desktop-lima/docker.sock /var/run/docker.sock

Start LocalStack using this command:

$ DEBUG=1 localstack start --network rancher

Rancher Desktop with containerd

If you are using the containerd runtime in Rancher Desktop, you’ll need to make some additional configurations. Ensure that the docker command is available through Rancher Desktop’s setup, or alternatively, use the nerdctl command line interface.

To start LocalStack with the containerd environment, use the following command:

$ DEBUG=1 DOCKER_CMD=nerdctl localstack start --network rancher

Windows

You can run Rancher Desktop on Windows using WSL2 (Windows Subsystem for Linux) with a Docker Compose setup for LocalStack.

Ensure Rancher Desktop is configured to use dockerd, and that the Docker socket is accessible in WSL2:

$ rancher-desktop settings set --docker

Initialize and start Rancher Desktop:

$ rancher-desktop --start

Modify your Docker Compose configuration to work with Rancher Desktop:

version: "3.8"
services:
  localstack:
    container_name: "${LOCALSTACK_DOCKER_NAME:-localstack-main}"
    image: localstack/localstack
    ports:
      - "127.0.0.1:4566:4566"
      - "127.0.0.1:4510-4559:4510-4559"
    networks:
      - rancher
    environment:
      - DEBUG=${DEBUG:-0}
    volumes:
      - "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack"
      - "/var/run/docker.sock:/var/run/docker.sock"
version: "3.8"
services:
  localstack:
    container_name: "${LOCALSTACK_DOCKER_NAME:-localstack-main}"
    image: localstack/localstack-pro
    ports:
      - "127.0.0.1:4566:4566"
      - "127.0.0.1:4510-4559:4510-4559"
      - "0.0.0.0:443:443"
    networks:
      - rancher
    environment:
      - LOCALSTACK_AUTH_TOKEN=${LOCALSTACK_AUTH_TOKEN:?}
      - DEBUG=${DEBUG:-0}
      - PERSISTENCE=${PERSISTENCE:-0}
    volumes:
      - "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack"
      - "/var/run/docker.sock:/var/run/docker.sock"

Finally, start the services using docker compose up or nerdctl compose up, depending on your configuration. This will launch your LocalStack instance configured to interact with Rancher Desktop.

Last modified February 10, 2025: add docs on rancher desktop (#1631) (3ef5f5996)