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

Getting dial tcp [::1]:32768: connect: connection refused from gitlab ci #191

Closed
glossd opened this issue Mar 1, 2020 · 11 comments
Closed

Comments

@glossd
Copy link
Contributor

glossd commented Mar 1, 2020

Locally it's all working, but when I run it in gitlab ci I get this error dial tcp [::1]:32768: connect: connection refused

In CI I configured DOCKER_HOST variable pointing to tcp://docker:2375

dockertest.NewPool("") should connect to docker daemon.

@aeneasr
Copy link
Member

aeneasr commented Mar 2, 2020

Which version of dockertest are you using? Are you sure tcp://docker:2375 is the URL where docker is running? You can confirm that by SSHing into the CI container.

@glossd
Copy link
Contributor Author

glossd commented Mar 14, 2020

dockertest version is v3.3.5 . I can assure you docker daemon is available on that url. I've run tests with java testcontainers library and everything was all right. But golang testcontainers showed the same error(((

@aeneasr
Copy link
Member

aeneasr commented Mar 14, 2020

That sounds like a misconfiguration then, CircleCI and TravisCI work fine. I don't think I can help you here.

@carlows
Copy link

carlows commented Jun 16, 2020

@aeneasr I'm getting this same error but looks to be raised when trying to connect to the container.

I'm trying a simple setup with docker and postgres:

docker build -t container .
docker network create --driver bridge test_network
docker run --network=test_network container go test ./...

results in: dial tcp: lookup docker on 127.0.0.11:53: no such host

The code:

pool, _ := dockertest.NewPool("")

resource, _ := pool.Run("postgres", "13-alpine", []string{"POSTGRES_PASSWORD=secret", "POSTGRES_DB=" + databaseName})

pgURL := fmt.Sprintf("postgres://postgres:secret@localhost:%s/%s?sslmode=disable", resource.GetPort("5432/tcp"), databaseName)

err = pool.Retry(func() error {
        var err error
        db, err = gorm.Open("postgres", pgURL)
	if err != nil {
		return err
	}
	return db.DB().Ping()
})

What is missing for this to work?

@aeneasr
Copy link
Member

aeneasr commented Jun 17, 2020

I don't use GitLab so I don't know, sorry!

@carlows
Copy link

carlows commented Jun 17, 2020

@aeneasr what I mentioned was not related to GitLab 😛 it is just a docker image I'm running locally.

@aeneasr
Copy link
Member

aeneasr commented Jun 17, 2020

This issue is about GitLab, if you have another problem please use a separate issue, thank you!

@glossd
Copy link
Contributor Author

glossd commented Aug 23, 2020

It took some time to figure it out)
In the examples the pool.Retry tries to connect to localhost whereas gitlab service runs docker:dind image (with container name docker) along side with the golang container where all the scripts get executed.
The database container runs inside that docker:dind container which means if I wish to connect to db container I should specify docker as a db host, not localhost

@glossd
Copy link
Contributor Author

glossd commented Aug 23, 2020

Example gitlab-ci.yml

go-test:
  stage: test
  image: golang:1.15
  services:
    - docker:dind
  variables:
    DOCKER_HOST: tcp://docker:2375
    DOCKER_DRIVER: overlay2
    DB_HOST_OF_YOUR_APP: docker
  script:
    - go test ./...
  • You need to have DB_HOST_OF_YOUR_APP environment variable setting your database host.

@glossd glossd closed this as completed Aug 23, 2020
@aeneasr
Copy link
Member

aeneasr commented Aug 25, 2020

Could you maybe add this to the readme so others can find this information quickly? :)

@glossd
Copy link
Contributor Author

glossd commented Sep 10, 2020

@aeneasr In order to make it work in gitlab ci the retry database host in the examples should be docker host, not localhost. Do you think it's worth to change the examples for the sake of gitlab ci or just put the note about it in readme?
Additionally the application's database host must be configurable through environment variables.
Should I add this note to the root readme?

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

3 participants