Expose database containers port


#1

I have a node container for the main app and a database container (dynamodb). Locally I start my dynamodb with docker run -p 8000:8000 bazaglia/dynamodb-local so that the host port 8000 is exposed and localhost:8000 is reachable. However, I didn’t figure out how to get a similar behavior in CircleCi 2.0. According to documentation, the first image in containerInfo would work like a “host”. But I still couldn’t get localhost:8000 accessible. My configuration is like this:

containerInfo:
  - image: node:4
  - image: bazaglia/dynamodb-local

Connecting to containers started with Docker Compose
#2

@bazaglia Did you specify port 8000 in your Dockerfile?


#3

@rohara Hey. I have EXPOSE 8000. As I understood, all exposed ports would be available within the main container (the first one listed in ContainerInfo). This is not working as I expected, though. I still unable to connect to my database instance.


#4

@bazaglia Does it take time for your container to start up before it is accessible? Can you try adding a sleep to your script?


#5

@rohara The container is accessible: it takes less then 1 second to start and there are other steps that take some time before actually connecting to database.

While carefully checking the logs I realized an address ( 172.17.0.2:5500) here:

====>> 0. Spin up Environment
Build-agent version 0.0.1915-bea1dcf (2016-12-26T15:42:09+0000)
Starting container node:4
  using image node@sha256:a1cc6d576734c331643f9c4e0e7f572430e8baf9756dc24dab11d87b34bd202e
Starting container bazaglia/dynamodb-local
  - Runner: time="2016-12-27T17:56:50Z" level=info msg="runner configured" address="172.17.0.2:5500" ui=streaming 

I’m not doing anything related with port 5500. Was it internally done by CircleCI? Also, I don’t know if it’s clear, but locally I have to run container with -p 8000:8000 to get it running in my host 8000 port. In CircleCI I understood this would be done automatically, but it’s not working as I would expect. Did I miss something?


#6

@bazaglia Can you provide a link the build where you see that information?


#7

@bazaglia Are you binding to 0.0.0.0:8000 in your Dockerfile? If you are not binding 0.0.0.0, that is your problem.


#8

@rohara I saw this information when building using local circleci. Running remotely it just fails when connecting to database.

I’m just exposing port 8000. This is my Dockerfile: https://hub.docker.com/r/bazaglia/dynamodb-local/~/dockerfile/

Is it enough?


#9

@bazaglia No, you need to bind to 0.0.0.0.


#10

@rohara Still not clear. In Docker docs (EXPOSE), it says you must use the -P flag to publish exposed ports. My initial though was that CircleCi use it internally to start containers, but you’re suggesting to bind to 0.0.0.0 in Dockerfile. How is that posible?

Thank you.


#11

@bazaglia I re-read what I wrote and I misleading. I’m very sorry. While you are exposing 8000, you need to bind the process to 0.0.0.0 or it will be inaccessible. You’re right that you can not expose 0.0.0.0:8000; you need to bind the java process to it.

With that said, I do not see a way to bind DynamoDB to 0.0.0.0 specifically. I will keep looking and get back to you.


Connecting to containers started with Docker Compose
#12

@rohara Thanks for helping me understanding. Feature suggestion: images in containerInfo could have an option that auto publish the exposed port (which is the same effect of docker run -P). This is useful in any situation where you have to communicate with other containers inside the main app container.


#13

A post was split to a new topic: Spinning up two containers that need to communicate


#14