Connecting to containers started with Docker Compose


#1

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 http://127.0.0.1:9000.

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   0.0.0.0:9000->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 0.0.0.0 as suggested here. What am I doing wrong? Is this use case supported in the current 2.0 beta state?


#2

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?


#3

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.


#4

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


#5

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.


#6

@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.


#7

@anon30319619

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: https://circleci.com/gh/meltwater/beat-classifier-api/23
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 127.0.0.1…
  • connect to 127.0.0.1 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`

thanks!


#8

me too @rohara @anon30319619


#9

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


#10

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


#11

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.


#12

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.


#13

@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.


#14

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


#15

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


#16

@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


#17

@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.


#18

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.


#19

@rohara Link to build: https://circleci.com/gh/bazaglia/confianet-insurance-api/20

Still getting the same error when running locally.


#20

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