testcontainers-go: [Bug]: Docs state docker context aware, but does not seem to work

Testcontainers version

v0.17.0

Using the latest Testcontainers version?

Yes

Host OS

OSX

Host arch

Arm64

Go version

1.19

Docker version

> docker version

Client: Docker Engine - Community
 Version:           23.0.0
 API version:       1.41 (downgraded from 1.42)
 Go version:        go1.19.5
 Git commit:        e92dd87c32
 Built:             Tue Jan 31 16:45:07 2023
 OS/Arch:           darwin/arm64
 Context:           colima

Server:
 Engine:
  Version:          20.10.20
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.7
  Git commit:       03df974ae9e6c219862907efdd76ec2e77ec930b
  Built:            Wed Oct 19 02:58:31 2022
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          v1.6.8
  GitCommit:        9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
 runc:
  Version:          1.1.4
  GitCommit:        5fd4c4d144137e991c4acebb2146ab1483a97925
 docker-init:
  Version:          0.19.0
  GitCommit:
> colima version

colima version 0.5.2
git commit: 6b5b6fe0540e708f0c9d6e8919fab292c671fc72

runtime: docker
arch: aarch64
client: v23.0.0
server: v20.10.20

Docker info

> docker info

Client:
 Context:    colima
 Debug Mode: false

Server:
 Containers: 115
  Running: 0
  Paused: 0
  Stopped: 115
 Images: 5
 Server Version: 20.10.20
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc io.containerd.runc.v2 io.containerd.runtime.v1.linux
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
 runc version: 5fd4c4d144137e991c4acebb2146ab1483a97925
 init version:
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 5.15.82-0-virt
 Operating System: Alpine Linux v3.16
 OSType: linux
 Architecture: aarch64
 CPUs: 2
 Total Memory: 1.93GiB
 Name: colima
 ID: VGCS:DVBU:ZQ3G:A75O:BZ5P:UNB7:7NJH:537I:2B7V:A2J5:KW4J:VH5A
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

What happened?

Starting a container via testcontainers returns the following error:

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?: failed to create container

Relevant log output

No response

Additional information

states the following: https://github.com/testcontainers/testcontainers-go/blob/ba569c031b4084de461f74e168a02bd9f1553874/docs/system_requirements/using_colima.md?plain=1#L6-L8

The context is set correctly…

# docker context show
colima

I can work work around that, but based on the docs assumed this was supposed to work.

If testcontainers is not context aware, I guess this is a feature request & not a bug report 😄

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 15
  • Comments: 16 (6 by maintainers)

Commits related to this issue

Most upvoted comments

Can confirm this is still not working on v0.25. The only workaround is:

sudo ln -sf $HOME/.colima/default/docker.sock /var/run/docker.sock

I had to run sudo ln -sf $HOME/.colima/default/docker.sock /var/run/docker.sock as a workaround, the simpler export DOCKER_HOST="unix://${HOME}/.colima/default/docker.sock" did not work for some reason either (that might be a separate bug!)

@mdelapenya I don’t think https://github.com/testcontainers/testcontainers-go/pull/2578/files fixes the problem as docs state

As of Colima v0.4.0 it’s recommended to set the active Docker context to use Colima. After the context is set Testcontainers for Go will automatically be configured to use Colima.

while it does seem one still need to link colima socket with

sudo ln -sf $HOME/.colima/default/docker.sock /var/run/docker.sock

(this is on colima version 0.6.9 and testcontainers v0.32.0)

I followed https://github.com/testcontainers/testcontainers-go/issues/815#issuecomment-2094646790 and I was able to step colima and run some of the project tests. I’m going to update the colima docs to include them

Thanks!

I had been facing similar issues. Turned out, I was looking at the wrong documentation. On checking documentation for Java, I found colima had to be started with flag --network-address for this to work well. Here are the steps I followed:

sudo ln -sf $HOME/.colima/default/docker.sock /var/run/docker.sock
colima stop
colima start --network-address
export TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=/var/run/docker.sock
export TESTCONTAINERS_HOST_OVERRIDE=$(colima ls -j | jq -r '.address')
export DOCKER_HOST="unix://${HOME}/.colima/default/docker.sock"

I’ve tried running the example code, and the errors have been fixed. Hope this helps!

Edit: Missed adding the relevant link

After digging into the code, adding a client.FromEnv option here will make the DOCKER_HOST workaround viable. It should make the docker client aware of the four environmental variables stated here. If there aren’t unwanted side effects that I’m not ware of, I can make a PR about this.