How do I setup docker based integration tests(ory/dockertest)

Dear CircleCI Team and Community

What I am trying to do
I recently discovered this Go package https://github.com/ory/dockertest that would permit me to really run my unit tests as units test since it let’s you spin up external services such databases as docker containers from within your code.

The initial problem problem
I can’t seem to correctly connect to the a container I just created.

After some googling I find out that circleci only permits you to run docker command only if you add setup_remote_docker which I did but now:

New problem now
I can’t even connect to the docker daemon which I previously could. Which I suspect is due the fact the remote docker listens on a different IP since the step where I run setup_remote_docker outputs something like this:

Allocating a remote Docker Engine

Assigned Docker Engine request id: 76766884
  provisioning: ......
Remote Docker engine created. Using VM 'default-1d81bced-****'
Created container accessible with:
  DOCKER_CERT_PATH=/tmp/docker-****
  DOCKER_HOST=tcp://35.196.181.97:2376
  DOCKER_MACHINE_NAME=****
  DOCKER_TLS_VERIFY=1
  NO_PROXY=127.0.0.1,localhost,circleci-internal-outer-build-agent,35.196.181.97:2376

Help me on how to do this
How to I bind localhost which is the default inside my code to the DOCKER_HOST ip address?

Hello @rugwirobaker

Have you seen our machine executor? I believe this will solve your issues entirely. Rather than using a Docker execution environment which does not have access to privileged containers (the reason for the remote docker environment), you can run in a true VM.

https://circleci.com/docs/2.0/executor-types/#using-machine

version: 2
jobs:
  build:
    machine: true

This should simplify the ability to use dockertest. Though one thing to note is it might be a little slower. However the remote docker environment should take about the same amount of “extra” time to allocate as the machine will take to spin up, so really there shouldn’t be much noticeable difference.

Let us know how this works for you :+1:

Does that mean that I am going to manually configure the environment?? For example installing golang. or there are image specific images for machine?

We only have a single VM “image” that is updated but we do not offer any pre-configured VM images at this time. You would need to install GoLang to the VM as a portion of the cofnig. This is something we can often automate with the use of Orbs but it does not appear we have an official GoLang orb yet, absolutely something we’ll add to the list (Though we’ll take PRs too!)

I don’t really have time to work on it since it’s my first time hearing abt orbs. I’m going with a work around for now.

The machine images seem to already a have go installed but the hustle getting it to work with Go Modules is even worse than trying to connect to remote_docker. At least in this case I only my tests fail.
Look at all this: :rofl::rofl::rofl:

I decide to go with my original setup. But is it possible to setup a proxy to the remote docker daemon so that I can keep using localhost inside my app.

1 Like

Welcome to continuous integration :joy_cat:

Incidentally, if you are making local changes, committing and pushing, I wonder if obtaining an SSH connection and compiling/re-running would be faster for you?

1 Like