Connecting to containers started with Docker Compose


In the same vein as this thread, I’m building my app as a Docker image, then starting it and some other containers to run integration tests against. The only problem is I can’t ping the app container on either http://localhost:9000 or

I run a docker ps immediately after starting the container and I see the following line:

5ee35ec536ae        mystuff/mycontainer:1.0.0    "mono DoMyStuff"   2 seconds ago       Up Less than a second>9000/tcp   mystuff_web_1

I spend a while waiting for the container to start, then try to connect. docker ps seems to suggest I should be able to connect to this container, but it just times out instead. The container is bound to as suggested here. What am I doing wrong? Is this use case supported in the current 2.0 beta state?


When you run the container locally, what output do you receive? Does it take a bit to start? Are you able to connect to it while it is running locally?


The Mono application running in it prints some startup info which I never see in the Circle build because the container is run as a daemon. My test script repeatedly pings the container for long enough that it should have ample time to start. I can indeed connect to it locally.


Can you share the build link with us so we can help you further investigate?


cc @rohara

if you are using remote-docker-engine you will not get access to containers through localhost.

The machine approach doesn’t have this limitation.


@rohara this build exhibits the problem.

@anon30319619 Can I change localhost to something else? If it’s dynamic, can I resolve the value from somewhere in the environment? I’dp refer not to use the machine config because AFAIK I can’t have a customised, cacheable Docker container to build in. Would love to be corrected if I’m wrong about this though.



how can I access the machines when spin up thru docker-compose?
if I ran the docker ps after run docker-compose I can see the images running

and what do you mean with machine approach?

Also another question:
this is the project:
I ran this:
`docker run -d -p 8990:8990 -e APPLICATION_EXPOSED_HOST=‘docker.local’ -e APPLICATION_DEBUG=‘True’ -e SEARCH_URL=‘http://searchservice{DOCKER_REPO}/{NAME}``

the docker is running however if I try to run

curl --retry 10 --retry-delay 5 -v http://localhost:8990
it not works I got this:

`* Rebuilt URL to: http://localhost:8990/

  • Hostname was NOT found in DNS cache
  • Trying ::1…
  • connect to ::1 port 8990 failed: Connection refused
  • Trying…
  • connect to port 8990 failed: Connection refused
  • Failed to connect to localhost port 8990: Connection refused
  • Closing connection 0
    curl: (7) Failed to connect to localhost port 8990: Connection refused
    Exited with code 7`



me too @rohara @anon30319619


@cpanato @jamwaffles Can you try using executorType: machine?


With machine do I need to install elixir, erlang nodejs? Or everything come in the machine?
I mean what is the necessary setup i need to do?

Thanks @rohara


I recommend just trying it. I do not have a definitive list of what is installed on the machine image, but you can certainly leverage Docker to pull in an image with what you need. Or, you can install them with apt.

I’ve been sticking mostly with the Docker executorType, but I’ve had great success with the machine in the several places I’ve used it now.


I’m reading this thread to see if it can help me solve my issue. The only executorType I saw in documentation was docker. Does machine means I will have to manually install docker and spin in my containers? If it’s the case it can help me as I would be able to use docker run with -P to expose the port I need for my database.


@jamwaffles @cpanato

You would need to run another docker container which will link a target container and then you can ping it by the name.


Hello @rohara thanks for the reply

  1. Where I can have more information about this executortype? there are any example? (also using docker / docker-compose) ?

  2. I change the executorType to machine and the first step checkout failed
    `mkdir: cannot create directory ‘/home/ubuntu/animal’: Permission denied
    Exited with code 1``

thanks for all


Sample Rails App Running Docker in a Container has a pretty complete example how to build, run & test your docker image.

The “magic” line is: docker exec railsapp curl -sSL http://localhost:3000 | grep "New Todo List"

Give your image a name (e.g. ‘myapp’) when you launch it and then try docker exec myapp curl --retry 10 --retry-delay 5 -v http://localhost:8990


@cpanato It’s brief, but Option 1 is all you need to get it running:

There is no base image, just pull and run Docker containers like you would locally.

You’re hitting that mkdir error because of a recent change to the machine. Change the ubuntu user to circleci and you’ll be good to go. I.e., /home/circleci/project


@rohara I changed to executorType: machine and could finally connect to my database. Tests run remotely are passing. :slight_smile:

However there are some points I noticed:

  1. Although remotely tests are passing, local tests are failing:
====>> 0. Spin up Environment
Build-agent version 0.0.2061-3efa9b7 (2017-01-06T00:56:47+0000)
Creating a dedicated  VM
Error: Unexpected environment preparation error: Machine configuration is not found
  1. Spin up Environment is taking almost 2 minutes. Is this expected?

  2. executorType: machine is not documented. Can I add nodejs to it just like it was possible in CircleCi 1.0? This way I could make my tests 30s faster as installing node step won’t be necessary.


Sounds like your environment variables have something that is upsetting the parser. Can you link to that build if it’s still a problem?

The startup time does seem a bit long, but I do not have any insight into the timing right now. I agree that two minutes is excessive to simply start.

You should be able to install nodejs in a similar fashion.


@rohara Link to build:

Still getting the same error when running locally.


@bazaglia Can you please let us know which error you are referring to? My apologies for missing it.