rockyourcode

Subscribe
Archives
April 12, 2022

rockyourcode: Testcontainers With Colima

Hello 👋! Thanks for subscribing.

Here is my latest article:

Testcontainers With Colima

Published on: 2022-04-09

tags: Java, Kotlin, Testing

Testcontainers is a Java library to support testing database operations with Docker containers.

The library needs a working Docker context to spin up the containers.

If you use Colima/Lima as a Docker replacement, you might come across the following error:

Could not find a valid Docker environment. Please see logs and check configuration
java.lang.IllegalStateException: Could not find a valid Docker environment. Please see logs and check configuration
    at org.testcontainers.dockerclient.DockerClientProviderStrategy.lambda$getFirstValidStrategy$4(DockerClientProviderStrategy.java)

You can override the docker host detection by providing the following environment variables (in your Bash/Zsh shell):

export TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=/var/run/docker.sock
export DOCKER_HOST="unix://${HOME}/.colima/docker.sock"

For Fish:

set -x TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE /var/run/docker.sock
set -x DOCKER_HOST unix://{$HOME}/.colima/docker.sock

I had to restart IntelliJ to make sure that the program picks up the changed environment.

Links:

  • How to configure Testcontainers to work with Colima as container runtime? #5034
  • Testcontainers

Thank you for reading my blog.

Don’t hesitate to reach out via email or Twitter!

Don't miss what's next. Subscribe to rockyourcode:
GitHub X
Powered by Buttondown, the easiest way to start and grow your newsletter.