question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to configure Testcontainers to work with Colima as container runtime?

See original GitHub issue

In the move away from paid Docker Desktop and towards alternatives, my organization has selected Colima as our official Docker engine for desktop development. After installing Colima via Homebrew on my mac, I’m able to run all my favorite docker commands as-is.

Colima sets up a new docker context, and sets itself as the active context:

> colima status
INFO[0000] colima is running
INFO[0000] runtime: docker
INFO[0000] arch: x86_64

> colima version
colima version 0.3.2
git commit: 272db4732b90390232ed9bdba955877f46a50552

runtime: docker
arch: x86_64
client: v20.10.11
server: v20.10.11

> docker context list
NAME        TYPE      DESCRIPTION                               DOCKER ENDPOINT
colima *    moby      colima                                    unix:///Users/ddowma/.colima/docker.sock
default     moby      Current DOCKER_HOST based configuration   unix:///var/run/docker.sock

As shown in the output above, there is still a default entry, and it points to unix:///var/run/docker.sock. However, I can see that no such file exists at that location:

> ls -l /var/run | grep 'docker.sock'
(empty output)

I noticed a problem when using Testcontainers 1.16.3 (and earlier versions) where Testcontainers can’t find the “active” docker socket. Here are the logs when running a test case that tries to spin up a DockerComposeContainer with the scenario that I describe above:

13:53:27.547 [Test worker] INFO  o.s.t.c.s.DefaultTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.spockframework.spring.SpringMockTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.event.ApplicationEventsTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener, org.springframework.test.context.event.EventPublishingTestExecutionListener]
13:53:27.563 [Test worker] DEBUG o.s.t.c.s.DefaultTestContextBootstrapper - Skipping candidate TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener] due to a missing dependency. Specify custom listener classes or make the default listener classes and their required dependencies available. Offending class: [javax/servlet/ServletContext]
13:53:27.577 [Test worker] INFO  o.s.t.c.s.DefaultTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@3d3599dc, org.springframework.test.context.event.ApplicationEventsTestExecutionListener@3375c9fb, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@6a8ea39d, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@71f8f1, org.springframework.test.context.support.DirtiesContextTestExecutionListener@111b6a5a, org.springframework.test.context.transaction.TransactionalTestExecutionListener@cbc4393, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@13b18bd2, org.springframework.test.context.event.EventPublishingTestExecutionListener@1c084f25, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@568bbf44, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@3845dedd, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@27353d1c, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@791a2fb8, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener@72e0ce40, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@64c555f7, org.spockframework.spring.SpringMockTestExecutionListener@6a9659ae]
13:53:27.888 [Test worker] DEBUG o.t.c.ParsedDockerComposeFile - Resolved dependency image for Docker Compose in /Users/ddowma/git/engineering-enablement/cars-publisher/cars-publisher-spring/build/resources/test/compose-kafka-zk-sr.yml: wurstmeister/zookeeper
13:53:27.904 [Test worker] DEBUG o.t.c.ParsedDockerComposeFile - Resolved dependency image for Docker Compose in /Users/ddowma/git/engineering-enablement/cars-publisher/cars-publisher-spring/build/resources/test/compose-kafka-zk-sr.yml: wurstmeister/kafka
13:53:27.904 [Test worker] DEBUG o.t.c.ParsedDockerComposeFile - Resolved dependency image for Docker Compose in /Users/ddowma/git/engineering-enablement/cars-publisher/cars-publisher-spring/build/resources/test/compose-kafka-zk-sr.yml: confluentinc/cp-schema-registry:6.1.0
13:53:27.920 [Test worker] DEBUG o.t.u.TestcontainersConfiguration - Testcontainers configuration overrides will be loaded from file:/Users/ddowma/.testcontainers.properties
13:53:27.943 [Test worker] WARN  o.t.u.TestcontainersConfiguration - Attempted to read Testcontainers configuration file at file:/Users/ddowma/.testcontainers.properties but the file was not found. Exception message: FileNotFoundException: /Users/ddowma/.testcontainers.properties (No such file or directory)
13:53:27.955 [Test worker] DEBUG o.t.d.DockerClientProviderStrategy - Trying out strategy: UnixSocketClientProviderStrategy
13:53:27.957 [Test worker] DEBUG o.t.d.DockerClientProviderStrategy - UnixSocketClientProviderStrategy: failed with exception InvalidConfigurationException (Could not find unix domain socket). Root cause NoSuchFileException (/var/run/docker.sock)
13:53:27.960 [Test worker] INFO  o.t.d.DockerMachineClientProviderStrategy - docker-machine executable was not found on PATH ([/Users/ddowma/.sdkman/candidates/java/current/bin, /Users/ddowma/.sdkman/candidates/groovy/current/bin, /usr/local/bin, /usr/bin, /bin, /usr/sbin, /sbin])
13:53:27.961 [Test worker] ERROR o.t.d.DockerClientProviderStrategy - Could not find a valid Docker environment. Please check configuration. Attempted configurations were:
13:53:27.961 [Test worker] ERROR o.t.d.DockerClientProviderStrategy -     UnixSocketClientProviderStrategy: failed with exception InvalidConfigurationException (Could not find unix domain socket). Root cause NoSuchFileException (/var/run/docker.sock)
13:53:27.961 [Test worker] ERROR o.t.d.DockerClientProviderStrategy - As no valid configuration was found, execution cannot continue

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

I found a work-around that solves this problem, but it isn’t a global solution. I have sudo rights on my workstation, so when I manually create a symlink from /var/run/docker.sock to /Users/ddowma/.colima/docker.sock, it works.

Thus, after running this command:

> sudo ln -s /Users/ddowma/.colima/docker.sock /var/run/docker.sock
Password:

> ls -l /var/run | grep 'docker.sock'
lrwxr-xr-x  1 root             daemon             33 Feb  8 14:00 docker.sock -> /Users/ddowma/.colima/docker.sock

Then my test case works fine. Here’s the relevant output from the test case immediately after creating that symlink that shows the docker environment startup working as expected. I filtered some DEBUG statements that didn’t add value, but left all the INFO statements in.

14:01:56.364 [Test worker] DEBUG o.t.c.ParsedDockerComposeFile - Resolved dependency image for Docker Compose in /Users/ddowma/git/engineering-enablement/cars-publisher/cars-publisher-spring/build/resources/test/compose-kafka-zk-sr.yml: wurstmeister/zookeeper
14:01:56.380 [Test worker] DEBUG o.t.c.ParsedDockerComposeFile - Resolved dependency image for Docker Compose in /Users/ddowma/git/engineering-enablement/cars-publisher/cars-publisher-spring/build/resources/test/compose-kafka-zk-sr.yml: wurstmeister/kafka
14:01:56.380 [Test worker] DEBUG o.t.c.ParsedDockerComposeFile - Resolved dependency image for Docker Compose in /Users/ddowma/git/engineering-enablement/cars-publisher/cars-publisher-spring/build/resources/test/compose-kafka-zk-sr.yml: confluentinc/cp-schema-registry:6.1.0
14:01:56.396 [Test worker] DEBUG o.t.u.TestcontainersConfiguration - Testcontainers configuration overrides will be loaded from file:/Users/ddowma/.testcontainers.properties
14:01:56.420 [Test worker] WARN  o.t.u.TestcontainersConfiguration - Attempted to read Testcontainers configuration file at file:/Users/ddowma/.testcontainers.properties but the file was not found. Exception message: FileNotFoundException: /Users/ddowma/.testcontainers.properties (No such file or directory)
14:01:56.433 [Test worker] DEBUG o.t.d.DockerClientProviderStrategy - Trying out strategy: UnixSocketClientProviderStrategy
14:01:56.894 [ducttape-0] DEBUG o.t.d.DockerClientProviderStrategy - Pinging docker daemon...
14:01:57.422 [Test worker] INFO  o.t.d.DockerClientProviderStrategy - Found Docker environment with local Unix socket (unix:///var/run/docker.sock)
14:01:57.422 [Test worker] DEBUG o.t.d.DockerClientProviderStrategy - Transport type: 'httpclient5', Docker host: 'unix:///var/run/docker.sock'
14:01:57.423 [Test worker] DEBUG o.t.d.DockerClientProviderStrategy - Checking Docker OS type for local Unix socket (unix:///var/run/docker.sock)
14:01:57.428 [Test worker] INFO  o.testcontainers.DockerClientFactory - Docker host IP address is localhost
14:01:57.470 [Test worker] INFO  o.testcontainers.DockerClientFactory - Connected to docker: 
  Server Version: 20.10.11
  API Version: 1.41
  Operating System: Alpine Linux v3.14
  Total Memory: 1988 MB
14:01:57.470 [Test worker] DEBUG o.testcontainers.DockerClientFactory - Ryuk is enabled
14:01:57.475 [Test worker] INFO  o.t.utility.ImageNameSubstitutor - Image name substitution will be performed by: DefaultImageNameSubstitutor (composite of 'ConfigurationFileImageNameSubstitutor' and 'PrefixingImageNameSubstitutor')
14:01:57.478 [Test worker] DEBUG o.t.u.PrefixingImageNameSubstitutor - No prefix is configured
14:01:57.478 [Test worker] DEBUG o.t.utility.ImageNameSubstitutor - Did not find a substitute image for testcontainers/ryuk:0.3.3 (using image substitutor: DefaultImageNameSubstitutor (composite of 'ConfigurationFileImageNameSubstitutor' and 'PrefixingImageNameSubstitutor'))
14:01:57.479 [Test worker] DEBUG o.t.s.c.g.d.c.command.AbstrDockerCmd - Cmd: testcontainers/ryuk:0.3.3
14:01:57.523 [Test worker] DEBUG o.t.utility.RegistryAuthLocator - Looking up auth config for image: testcontainers/ryuk:0.3.3 at registry: index.docker.io
14:01:57.523 [Test worker] DEBUG o.t.utility.RegistryAuthLocator - RegistryAuthLocator has configFile: /Users/ddowma/.docker/config.json (exists) and commandPathPrefix: 
14:01:57.524 [Test worker] DEBUG o.t.utility.RegistryAuthLocator - registryName [index.docker.io] for dockerImageName [testcontainers/ryuk:0.3.3]
14:01:57.525 [Test worker] DEBUG o.t.utility.RegistryAuthLocator - No matching Auth Configs - falling back to defaultAuthConfig [null]
14:01:57.525 [Test worker] DEBUG o.t.d.AuthDelegatingDockerClientConfig - Effective auth config [null]
14:01:57.538 [Test worker] DEBUG o.t.s.c.g.d.c.command.AbstrDockerCmd - Cmd: org.testcontainers.shaded.com.github.dockerjava.core.command.CreateContainerCmdImpl@1ea5f0de[name=testcontainers-ryuk-156612ea-886b-4884-a157-50e191f885a9,hostName=<null>,domainName=<null>,user=<null>,attachStdin=<null>,attachStdout=<null>,attachStderr=<null>,portSpecs=<null>,tty=<null>,stdinOpen=<null>,stdInOnce=<null>,env=<null>,cmd=<null>,healthcheck=<null>,argsEscaped=<null>,entrypoint=<null>,image=testcontainers/ryuk:0.3.3,volumes=Volumes(volumes=[]),workingDir=<null>,macAddress=<null>,onBuild=<null>,networkDisabled=<null>,exposedPorts=ExposedPorts(exposedPorts=[8080/tcp]),stopSignal=<null>,stopTimeout=<null>,hostConfig=HostConfig(binds=[/var/run/docker.sock:/var/run/docker.sock:rw], blkioWeight=null, blkioWeightDevice=null, blkioDeviceReadBps=null, blkioDeviceWriteBps=null, blkioDeviceReadIOps=null, blkioDeviceWriteIOps=null, memorySwappiness=null, nanoCPUs=null, capAdd=null, capDrop=null, containerIDFile=null, cpuPeriod=null, cpuRealtimePeriod=null, cpuRealtimeRuntime=null, cpuShares=null, cpuQuota=null, cpusetCpus=null, cpusetMems=null, devices=null, deviceCgroupRules=null, deviceRequests=null, diskQuota=null, dns=null, dnsOptions=null, dnsSearch=null, extraHosts=null, groupAdd=null, ipcMode=null, cgroup=null, links=[], logConfig=LogConfig(type=null, config=null), lxcConf=null, memory=null, memorySwap=null, memoryReservation=null, kernelMemory=null, networkMode=null, oomKillDisable=null, init=null, autoRemove=true, oomScoreAdj=null, portBindings={8080/tcp=[Lcom.github.dockerjava.api.model.Ports$Binding;@bfeaa61}, privileged=false, publishAllPorts=null, readonlyRootfs=null, restartPolicy=null, ulimits=null, cpuCount=null, cpuPercent=null, ioMaximumIOps=null, ioMaximumBandwidth=null, volumesFrom=null, mounts=null, pidMode=null, isolation=null, securityOpts=null, storageOpt=null, cgroupParent=null, volumeDriver=null, shmSize=null, pidsLimit=null, runtime=null, tmpFs=null, utSMode=null, usernsMode=null, sysctls=null, consoleSize=null),labels={org.testcontainers=true},shell=<null>,networkingConfig=<null>,ipv4Address=<null>,ipv6Address=<null>,aliases=<null>,authConfig=<null>,platform=<null>]
14:01:58.022 [Test worker] DEBUG o.t.s.c.g.d.c.e.InspectContainerCmdExec - GET: DefaultWebTarget{path=[/containers/3d81f73b9b4365657236d017aa32d0d4945e2c1eb0993d09e64e06e4591ab3d0/json], queryParams={}}
14:01:58.096 [testcontainers-ryuk] DEBUG o.t.utility.ResourceReaper - Sending 'label=org.testcontainers%3Dtrue&label=org.testcontainers.sessionId%3D156612ea-886b-4884-a157-50e191f885a9' to Ryuk
14:01:58.099 [testcontainers-ryuk] DEBUG o.t.utility.ResourceReaper - Received 'ACK' from Ryuk
14:01:58.101 [Test worker] INFO  o.testcontainers.DockerClientFactory - Ryuk started - will monitor and terminate Testcontainers containers on JVM exit
14:01:58.101 [Test worker] DEBUG o.testcontainers.DockerClientFactory - Checks are enabled
14:01:58.101 [Test worker] INFO  o.testcontainers.DockerClientFactory - Checking the system...
14:01:58.102 [Test worker] INFO  o.testcontainers.DockerClientFactory - ✔︎ Docker server version should be at least 1.6.0
14:01:58.230 [Test worker] INFO  o.testcontainers.DockerClientFactory - ✔︎ Docker environment should have more than 2GB free disk space
14:01:58.234 [testcontainers-ryuk] DEBUG o.t.utility.ResourceReaper - Sending 'label=com.docker.compose.project%3Dn9eh7nsc2dkm' to Ryuk
14:01:58.234 [Test worker] INFO  o.t.c.DockerComposeContainer - Preemptively checking local images for 'confluentinc/cp-schema-registry:6.1.0', referenced via a compose file or transitive Dockerfile. If not available, it will be pulled.
14:01:58.234 [Test worker] DEBUG o.t.s.c.g.d.c.command.AbstrDockerCmd - Cmd: confluentinc/cp-schema-registry:6.1.0
14:01:58.236 [testcontainers-ryuk] DEBUG o.t.utility.ResourceReaper - Received 'ACK' from Ryuk
14:01:58.239 [Test worker] INFO  o.t.c.DockerComposeContainer - Preemptively checking local images for 'wurstmeister/zookeeper:latest', referenced via a compose file or transitive Dockerfile. If not available, it will be pulled.
14:01:58.239 [Test worker] DEBUG o.t.s.c.g.d.c.command.AbstrDockerCmd - Cmd: wurstmeister/zookeeper:latest
14:01:58.243 [Test worker] INFO  o.t.c.DockerComposeContainer - Preemptively checking local images for 'wurstmeister/kafka:latest', referenced via a compose file or transitive Dockerfile. If not available, it will be pulled.
14:01:58.243 [Test worker] DEBUG o.t.s.c.g.d.c.command.AbstrDockerCmd - Cmd: wurstmeister/kafka:latest
14:01:58.254 [Test worker] DEBUG o.t.u.PrefixingImageNameSubstitutor - No prefix is configured
14:01:58.254 [Test worker] DEBUG o.t.utility.ImageNameSubstitutor - Did not find a substitute image for docker/compose:1.29.2 (using image substitutor: DefaultImageNameSubstitutor (composite of 'ConfigurationFileImageNameSubstitutor' and 'PrefixingImageNameSubstitutor'))
14:01:58.257 [Test worker] DEBUG o.t.s.c.g.d.c.command.AbstrDockerCmd - Cmd: ListImagesCmdImpl[imageNameFilter=<null>,showAll=false,filters=org.testcontainers.shaded.com.github.dockerjava.core.util.FiltersBuilder@0]
14:01:58.266 [Test worker] DEBUG o.t.images.AbstractImagePullPolicy - Using locally available and not pulling image: docker/compose:1.29.2
14:01:58.266 [Test worker] DEBUG 🐳 [docker/compose:1.29.2] - Set env COMPOSE_FILE=/Users/ddowma/git/engineering-enablement/cars-publisher/cars-publisher-spring/build/resources/test/compose-kafka-zk-sr.yml
14:01:58.269 [Test worker] DEBUG 🐳 [docker/compose:1.29.2] - Starting container: docker/compose:1.29.2
14:01:58.269 [Test worker] DEBUG 🐳 [docker/compose:1.29.2] - Trying to start container: docker/compose:1.29.2 (attempt 1/1)
14:01:58.269 [Test worker] DEBUG 🐳 [docker/compose:1.29.2] - Starting container: docker/compose:1.29.2
14:01:58.269 [Test worker] INFO  🐳 [docker/compose:1.29.2] - Creating container for image: docker/compose:1.29.2
14:01:59.036 [Test worker] INFO  🐳 [docker/compose:1.29.2] - Container docker/compose:1.29.2 is starting: 19d5b5146235a3528adabaed4837f43d4c18302b1261f8e3167ed74f49d5040c
14:02:02.180 [Test worker] DEBUG o.t.c.w.s.HostPortWaitStrategy - Liveness check ports of /great_albattani is empty. Not waiting.
14:02:02.180 [Test worker] INFO  🐳 [docker/compose:1.29.2] - Container docker/compose:1.29.2 started in PT3.911682S
14:02:02.184 [Test worker] INFO  🐳 [docker/compose:1.29.2] - Docker Compose container is running for command: up -d
14:02:02.188 [docker-java-stream--579305284] INFO  🐳 [docker/compose:1.29.2] - STDERR: The Docker Engine you're using is running in swarm mode.
14:02:02.188 [docker-java-stream--579305284] INFO  🐳 [docker/compose:1.29.2] - STDERR: 
14:02:02.188 [docker-java-stream--579305284] INFO  🐳 [docker/compose:1.29.2] - STDERR: Compose does not use swarm mode to deploy services to multiple nodes in a swarm. All containers will be scheduled on the current node.
14:02:02.189 [docker-java-stream--579305284] INFO  🐳 [docker/compose:1.29.2] - STDERR: 
14:02:02.189 [docker-java-stream--579305284] INFO  🐳 [docker/compose:1.29.2] - STDERR: To deploy your application across the swarm, use `docker stack deploy`.
14:02:02.189 [docker-java-stream--579305284] INFO  🐳 [docker/compose:1.29.2] - STDERR: 
14:02:02.189 [docker-java-stream--579305284] INFO  🐳 [docker/compose:1.29.2] - STDERR: Creating network "n9eh7nsc2dkm_default" with the default driver
14:02:02.189 [Test worker] INFO  🐳 [docker/compose:1.29.2] - Docker Compose has finished running
14:02:02.189 [docker-java-stream--579305284] INFO  🐳 [docker/compose:1.29.2] - STDERR: Creating n9eh7nsc2dkm_zookeeper_1 ... 
14:02:02.189 [docker-java-stream--579305284] INFO  🐳 [docker/compose:1.29.2] - STDERR: Creating n9eh7nsc2dkm_zookeeper_1 ... done
14:02:02.190 [docker-java-stream--579305284] INFO  🐳 [docker/compose:1.29.2] - STDERR: Creating n9eh7nsc2dkm_schemaregistry_1 ... 
14:02:02.190 [docker-java-stream--579305284] INFO  🐳 [docker/compose:1.29.2] - STDERR: Creating n9eh7nsc2dkm_kafka_1          ... 
14:02:02.190 [docker-java-stream--579305284] INFO  🐳 [docker/compose:1.29.2] - STDERR: Creating n9eh7nsc2dkm_kafka_1          ... done
14:02:02.190 [docker-java-stream--579305284] INFO  🐳 [docker/compose:1.29.2] - STDERR: Creating n9eh7nsc2dkm_schemaregistry_1 ... done

What I glean from this exercise is that Testcontainers is taking the default docker context (or maybe not checking at all), and isn’t looking at the active context. If my assessment of the problem is correct, can that situation be addressed?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:28 (10 by maintainers)

github_iconTop GitHub Comments

22reactions
codingdiscercommented, Feb 11, 2022

I can confirm that this works - meaning setting only these 2 env vars (and not messing with Ryuk at all):

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

Thank you @benhexagon for the suggestion, and @kiview for the follow-ups.

4reactions
tiagomotacommented, Nov 18, 2022

Hey 👋 During my adventure of setting up a working environment to run testcontainers on macOS using a Lima-VM based solution, I stumbled upon this issue. It helped me figure out some details. Therefore, I want to share my findings, so that others in the same situation can try for themselves.

Setup with Colima + testcontainers

During my tests, I couldn’t make ryuk work with colima out of the box. I managed to do it by starting the VM with an assigned IP and then overriding TESTCONTAINERS_HOST_OVERRIDE with it. From that point onwards, together with what is described in the documentation, all my project’s tests worked flawlessly.

  1. Install Colima: brew install colima
  2. Install docker: brew install docker
  3. Start Colima with an assigned IP address: colima start —network-address
  4. Colima automatically creates and sets a docker context named colima, therefore docker commands on the command line work out of the box
  5. To use with testcontainers, make sure the following environment variables are set on your session:
    • export TESTCONTAINERS_HOST_OVERRIDE=$(colima ls -j | jq -r '.address')
    • export TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=/var/run/docker.sock
    • export DOCKER_HOST=unix://$HOME/.colima/default/docker.sock

Setup with Lima-VM + testcontainers

This one was a bit trickier. Based on the thought process behind the colima setup, I searched how I could get an IP as I had with colima. Eventually, I got to this issue, which lead me to the Lima Network documentation. From there, I tried using socket_vmnet to get an IP address of the VM I could use on TESTCONTAINERS_HOST_OVERRIDE. From that moment, all my project’s tests worked flawlessly with ryuk enabled.

  1. Install Lima: brew install lima
  2. Install docker: brew install docker
  3. Download and extract socket_vmnet: mkdir -p /tmp/socket_vmnet && curl -L https://github.com/lima-vm/socket_vmnet/archive/refs/tags/v1.0.0-alpha.0.tar.gz | tar --strip-components=1 -xvz -C /tmp/socket_vmnet
  4. Install socket_vmnet: cd /tmp/socket_vmnet && sudo make PREFIX=/opt/socket_vmnet install && cd -
  5. Add Lima to sudoers to enable it to start and stop [socket_vmnet](socket_vmnet: limactl sudoers | sudo tee /etc/sudoers.d/lima
  6. Start a Lima with rootful docker runtime: limactl start --name=docker template://docker-rootful | true
  7. Edit the configuration of the newly created VM: limactl stop docker && limactl edit docker
  8. Add the following yaml to end of file, to set the network in the VM to bridged:
networks:
  - lima: bridged
  1. For command line usage:
    • Create a new lima-docker context: docker context create lima-docker --docker "host=unix://$HOME/.lima/docker/sock/docker.sock"
    • Use that new context: docker context use lima-docker
    • Test it: docker run hello-world
  2. To use with testcontainers, make sure the following environment variables are set on your session:
    • export TESTCONTAINERS_HOST_OVERRIDE=$(limactl shell docker ip a show lima0 | grep 'inet '| awk '{print $2}' | cut -f1 -d"/")
    • export TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=/var/run/docker.sock
    • export DOCKER_HOST=$(limactl list docker --format 'unix://{{.Dir}}/sock/docker.sock')

There might be better ways of setting up Lima-VM, but colima setup was easier and good enough for me, so I stopped there.

@kiview I’m not sure if this is the best place to share info like this. If not, sorry in advance 🙏

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testcontainers With Colima | rockyourcode
Testcontainers is a Java library to support testing database operations with Docker containers. The library needs a working Docker context ...
Read more >
Using Colima with Docker - Testcontainers for Go
Colima is a container runtime which integrates with Docker's tooling and can be configured in various ways. As of Colima v0.4.0 it's recommended...
Read more >
Colima, Apple M1 and Testcontainers - Vivid Code
Set up Colima ... Colima server is available at the sock address unix:///Users/${HOME}/.colima/default/docker.sock . You can use docker client to ...
Read more >
AtomicJar on Twitter: "Looking for options to run your ...
How to use Docker Machine, Minikube, and Docker Desktop on Windows and macOS ... Linux) with minimal setup - GitHub - abiosoft/colima: Container...
Read more >
Replacing Docker Desktop for Mac with Colima - Arthur Koziel
Colima provisions the Docker container runtime in a Lima VM, configures the docker CLI on macOS and handles port-forwarding and volume ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found