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

Error when creating docker container: no such host #78

Closed
imulab opened this issue Feb 12, 2017 · 21 comments
Closed

Error when creating docker container: no such host #78

imulab opened this issue Feb 12, 2017 · 21 comments
Labels

Comments

@imulab
Copy link

imulab commented Feb 12, 2017

(Docker version is 1.13.1)

I was using the example MongoDB code to create a mongo container in my test case and encountered this no such host error when connecting:

Post http://unix.sock/containers/create?: dial tcp: lookup unix.sock: no such host

Suspected a OS X platform issue, I also tried to run the test case on Travis CI with the following configuration:

language: go
sudo: required

go:
- 1.7

services:
- docker

but got the same error.

Here is the code that caused the problem, it is essentially same with the example code:

func connectToDockerMongo(t *testing.T) (*dockertest.Pool, *dockertest.Resource) {
	pool, err := dockertest.NewPool("")
	fatalIfError(t, err)

	dockerResource, err := pool.Run("mongo", "3.3", []string{""})
	fatalIfError(t, err)

	err = pool.Retry(func() error {
		var e error
		session, e := mgo.Dial(fmt.Sprintf("localhost:%s", dockerResource.GetPort("27017")))
		if e != nil {
			t.Error(e)
			return e
		}
		return session.Ping()
	})
	fatalIfError(t, err)

	return pool, dockerResource
}

Basically, pool.Run("mongo", "3.3", []string{""}) is failing.

Could someone please help. Thanks!

@aeneasr
Copy link
Member

aeneasr commented Feb 12, 2017

Looks like the socket changed (not sure to what, I would have to investigate). Try connecting with NewPool("http://localhost:2375")

@imulab
Copy link
Author

imulab commented Feb 12, 2017

Connecting to localhost:2375 yields a fast cannot connect to Docker endpoint error.

@aeneasr
Copy link
Member

aeneasr commented Feb 12, 2017

Ok, you need to see for yourself where docker is listening on and provide that value as an argument to newpool

@imulab
Copy link
Author

imulab commented Feb 12, 2017

thx, I ll try that

@galaxydi
Copy link

How to check the listening file in MAC, I found it's hard to find out where is the docker daemon config on MAC?

The problem was resovled?

@calvn
Copy link
Contributor

calvn commented Apr 9, 2017

Are you using docker-machine, or docker for MacOS? If it's the former, you need to find the IP of the VM and connect to it instead of localhost. Hope this helps!

@pbarker
Copy link
Contributor

pbarker commented Jun 2, 2017

Just hit this as well, if you try an test hydra in an alpine container this breaks it.

@aeneasr
Copy link
Member

aeneasr commented Jun 5, 2017

I'm hitting the same issue on Windows now, will investigate soon.

@aeneasr aeneasr added the bug label Jun 5, 2017
@pbarker
Copy link
Contributor

pbarker commented Jun 5, 2017

So mine ended up being that I needed network_mode: "host", but that is currently not working on a mac seen here docker/for-mac#1031. I just found a workaround for the time being.

@aeneasr
Copy link
Member

aeneasr commented Jun 6, 2017

Well, you simply need to expose http in the docker general config:

image

We should probably investigate adding TLS soon here.

@pbarker
Copy link
Contributor

pbarker commented Jun 6, 2017

must be a windows thing, don't have that on docker-for-mac yet ¯_(ツ)_/¯

@pinkisemils
Copy link

OSX won't require TLS because Docker on OSX does not use a TCP socket but rather a Unix socket that is only accessible by local processes anyway and all of the unixy file permissions apply.

@aeneasr
Copy link
Member

aeneasr commented Jun 15, 2017

right, that makes sense! so does it work now for everyone?

@rugwirobaker
Copy link

I am having this same issue while running tests in circleci. If I am not mistaken it clearly can connect to the docker daemon but can not start the container. since if fails on this line:

container, err := pool.Run("postgres", "alpine", config)
if err != nil {
log.Fatalf("Could not start container: %s", err)
}
returning:

Could not start container: : dial unix /var/run/docker.sock: connect: no such file or directory

environment: circleci linux

@aeneasr
Copy link
Member

aeneasr commented Jun 24, 2019 via email

@rugwirobaker
Copy link

rugwirobaker commented Jun 25, 2019

I have been working on it and the problems seems to be that circleci allows you yo run docker commands only when you setup a local docker host. In my tests am connecting to localhost but the remote docker daemon is of course remote. I have tried using the DOCKER_HOST to no effect. S does anyone know if there is a way you can proxy your local clients requests to a remote docker without having to use it's address directly??

@fanadol
Copy link

fanadol commented Jul 3, 2020

I also experience this on gitlab ci.

@avarghese-sqsp
Copy link

Is this still a problem?

@aeneasr aeneasr closed this as completed Apr 27, 2021
@AlexeyInc
Copy link

AlexeyInc commented May 13, 2024

Still have above problem

Getting dial unix /var/run/docker.sock: connect: no such file or directory when trying to run docker container with dockertest on mac M1

@farshadahmadi
Copy link

Still have above problem

Getting dial unix /var/run/docker.sock: connect: no such file or directory when trying to run docker container with dockertest on mac M1

Got the same issue today! Any solution?

@robmonte
Copy link

I was seeing the same error as well. For me, going into the settings and then the advanced settings section of Docker Desktop, I enabled the option Allow the default Docker socket to be used (requires password). Afterwards my tests worked again.

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

No branches or pull requests