Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot connect to the Docker daemon ($DOCKER_HOST - non typical docker.sock location - no root permission ) #161

Closed
jpmartins opened this issue Sep 12, 2024 · 10 comments

Comments

@jpmartins
Copy link

Hello I am having error starting the testcontainers/ryuk on my docker daemon

docker run testcontainers/ryuk

2024/09/12 12:10:28 Pinging Docker...
panic: **Cannot connect to the Docker daemon at unix:///var/run/docker.sock**. Is the docker daemon running?

goroutine 1 [running]:
main.main()
/go/src/github.com/testcontainers/moby-ryuk/main.go:36 +0x457
@jpmartins
Copy link
Author

On my docker host the dock.sock (DOCKER ENDPOINT) is at $DOCKER_HOST (unix://$HOME/.colima/default/docker.sock).

Anyone can help?

@jpmartins
Copy link
Author

ls -ltr $HOME/.colima/default/docker.sock
srw-------  1 P002979  staff  0 Sep 12 10:13 /Users/xxx/.colima/default/docker.sock
colima status
INFO[0000] colima is running using QEMU                 
INFO[0000] arch: x86_64                                 
INFO[0000] runtime: docker                              
INFO[0000] mountType: sshfs                             
INFO[0000] socket: unix:///Users/xxx/.colima/default/docker.sock 
docker ps -a | head -n 3
CONTAINER ID   IMAGE                       COMMAND                  CREATED              STATUS                          PORTS                                                                                                                                           NAMES
07b8730e8c2b   testcontainers/ryuk         "/app"                   About a minute ago   Exited (2) About a minute ago                                                                                                                                                   elated_bassi
9440a2d34563   testcontainers/ryuk         "/app"                   3 minutes ago        Exited (2) 3 minutes ago                                                                                                                                                        musing_hypatia
docker run -v $HOME/.colima/default/docker.sock:/var/run/docker.sock -e RYUK_PORT=8080 -p 8080:8080 testcontainers/ryuk
2024/09/12 13:29:30 Pinging Docker...
panic: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

goroutine 1 [running]:
main.main()
	/go/src/github.com/testcontainers/moby-ryuk/main.go:36 +0x457

@mdelapenya
Copy link
Member

Hi @jpmartins I guess you already took a look at https://golang.testcontainers.org/system_requirements/using_colima/

Did you follow the steps in that guide?

@jpmartins
Copy link
Author

jpmartins commented Sep 12, 2024

Thanks for you input mdelapenya.

That guide, on the "other applications that are unaware of Docker context the following workaround" requires something I do not have permission to do, this is a work macbook and on it I do not have a way to do:

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

It would be nice to have other alternatives... currently my workaround is using docker desktop instead of colima.

@jpmartins-ca
Copy link

jpmartins-ca commented Sep 13, 2024

Hi @jpmartins I guess you already took a look at https://golang.testcontainers.org/system_requirements/using_colima/

Did you follow the steps in that guide?

By the way, some of the instructions I identified what seem to be issues that I could not figure out how to fix. More specifically the TESTCONTAINERS_HOST_OVERRIDE initialisation is returning null:

export TESTCONTAINERS_HOST_OVERRIDE=$(colima ls -j | jq -r '.address')
 ~ % echo $TESTCONTAINERS_HOST_OVERRIDE
null
 ~ % echo $(colima ls -j | jq -r '.address') 
null
 ~ % jq --version
jq-1.7.1
 ~ % colima --version
colima version 0.7.5
 ~ % echo $(colima ls -j | jq -r '.address')
null
 ~ % echo $(colima ls -j | jq -r)           
{ "name": "default", "status": "Running", "arch": "x86_64", "cpus": 2, "memory": 4294967296, "disk": 64424509440, "runtime": "docker" }

@jpmartins-ca
Copy link

jpmartins-ca commented Sep 13, 2024

Suspect some of the issues might be related with running colima emulating x86_64 under a arm64 cpu.

@kiview
Copy link
Member

kiview commented Sep 13, 2024

Hi @jpmartins, why are you running Ryuk manually using the Docker CLI? Testcontainers tries to configure the socket location provided to Ryuk depending on your environment. If this is not working, you should open the issue on the Testcontainers side.

When running Ryuk manually (which is not something Testcontainers users need to do, this is only relevant for Testcontainers developers), you need to mount the socket as per README:

docker run -v /var/run/docker.sock:/var/run/docker.sock -e RYUK_PORT=8080 -p 8080:8080 

So, if this is a Testcontainers issue, let's please close this issue here and instead open it in the corresponding Testcontainers language project.

@jpmartins-ca
Copy link

jpmartins-ca commented Sep 13, 2024

I had a ticket on testcontainers... I closed it and opened this one since the error is on starting the ryuk container... calling it directly has the goal to try to replicate the issue by the command line outside testcontainers. To try to show, that from my perspective there are issues on ryuk side.

Are you saying only a ticket on testcontainers-java side can troubleshoot this?

Since I have limited permissions, it is not possible to have default/standard location of docker.sock on my machine, so /var/run/docker.sock does not exist on my machine, and I do not have admin or sudo rights to create it. That is why I pointed to the existing /Users/_user/.docker/run/docker.sock while starting the ryuk.

For documentation proposes on issues with start ryuk, if your docker-desktop on arm64 suddenly stops working with:

error while creating mount source path '/host_mnt/Users/P002979/.docker/run/docker.sock': mkdir /host_mnt/Users/_user/.docker/run/docker.sock: operation not supported

Following the docker/for-mac#4859 (comment), and changing to "osxfs (Legacy)" in the Advanced Docker Destkop worked for my case.

@kiview
Copy link
Member

kiview commented Sep 13, 2024

The important thing here is, that we don;t start to mix Testcontainers features into this issue then if we want to specifically debug running Ryuk (like TESTCONTAINERS_HOST_OVERRIDE or general Colima instruction for Testcontainers usage, which have nothing to do with running Ryuk manually).

In your case, I guess you would need to run Ryuk like this (I didn't see you doing it in your previous posts), although I am entirely not sure how to indicate to Colima, to mount the socket from within the Colima VM instead of mounting through the host (also see abiosoft/colima#688 (comment)):

docker run -v  /var/run/docker.sock:/var/run/docker.sock -e RYUK_PORT=8080 -p 8080:8080

currently my workaround is using docker desktop instead of colima.

Using Docker Desktop is the officially supported runtime by Testcontainers, we don't officially support other container runtimes and it is up to users configure things in a way to work similar to Docker Desktop.

Are you saying only a ticket on testcontainers-java side can troubleshoot this?

Since it seems your goal is about running testcontainers-java, and not about manually running Ryuk, yes, the correct approach is go through testcontainers-java.

@jpmartins
Copy link
Author

jpmartins commented Sep 13, 2024

You were right, sorry for the inconvenience, hope you have a nice weekend, and thank you for the help on Slack.

As you now know Kevin, with -v /var/run/docker.sock:/var/run/docker.sock alone did not cut it, the issue was also some leftover environment variables from my first attempt with colima, the DOCKER_HOST env var was set to point to docker.sock of Docker-Desktop. DOCKER_HOST should not be set for Docker-Desktop.

Temporary disable of ryuk is an option to continue exploring/learning, but will have the test container not being discarded that way.

Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants