Run Testcontainers with Rancher Desktop on macOS

Run Testcontainers with Rancher Desktop on macOS

Rancher Desktop is a free/open source alternative to Docker Desktop without licensing restrictions. That makes Rancher Desktop an ideal substitution for Docker Desktop, especially for businesses that do not have the budget for Docker Desktop. Even though Rancher Desktop is a Docker Desktop drop and replacement program, it needs some additional configurations to make it work with Testcontainers. In this article, we focus on how to run Testcontainers tests with Rancher Desktop on macOS, specifically the Apple silicon chip.

Why Rancher Desktop

As stated before, for many businesses, bearing at least $9/month per user is unjustifiable to use Docker Desktop. Rancher Desktop supports everything that Docker Desktop offers, plus many more features, such as support for containerd. Besides that, Rancher Desktop is open-source software backed by a large company, namely SUSE. Therefore, there are no concerns about it being abandoned, unlike many solo-maintained repositories. All these reasons make Rancher Desktop an ideal alternative to Docker Desktop.

For the most part, transitioning from Docker Desktop to Rancher Desktop is seamless, at least in our experience. The only difficulty one may encounter is running Testcontainers tests with it, which can be resolved with a few configuration tweaks.

Rancher Desktop configurations for Testcontainers

In this section, we go through steps that you need to take to ensure Testcontainers works with Rancher Desktop.

Step #1: Delete docker.sock file

If previously you installed Docker Desktop on your machine, you need to ensure the docker.sock file is removed. To ensure that, run the below command,

$ sudo rm -rvf /var/run/docker.sock

Step #2: Switch container engine to Moby

By default, Rancher Desktop is configured to operate with containerd, which does not play nicely with Testcontainers. To resolve this, you need to change the container engine to Moby. From Preferences in the Rancher Desktop application, go to the Container Engine section and select dockerd (Moby).

Step #3: Disable Kubernetes

The next step is to disable Kubernetes. From the Preferences menu, select Kubernetes and make sure Enable Kubernetes is disabled.

Rancher Desktop Settings - Kubernetes

Step #4: Symlink docker.sock file

Since we removed the docker.sock file, we need to ensure that when switching to the Moby engine, the file is created. Otherwise, Docker does not function correctly. To test, run the command below:

$ ls /var/run/docker.sock

If the file exists, you can skip the rest of the step. Otherwise, if you received an error similar to the one below, you need to create a symlink docker.sock file.

ls: /var/run/docker.sock: No such file or directory

To create a symlink, run this command:

$ sudo ln -s $HOME/.rd/docker.sock /var/run/docker.sock

Lastly, run the ls command once again to ensure the file is successfully symlinked.

Conclusion

Rancher Desktop is a great alternative to Docker Desktop for both businesses and free/open source advocates. It is open source and has no licensing or usage fee. However, like any container software, Rancher Desktop is not completely compatible with software and libraries that rely on Docker yet. One example is Testcontainers, which requires some minor configurations to work on Rancher Desktop. Other than that, from a usability perspective, Rancher Desktop is stable, and since its UI is similar to Docker Desktop, it does not impose any learning curve on users.

Inline/featured images credits