Error when start docker-compose


#1

Hello

The test step for my project need run the docker-compose to spin some services like postgres, when I run the docker-compose I got this error:

docker-compose up -d

Creating network "animal_default" with the default driver Pulling postgres (postgres:latest)... latest: Pulling from library/postgres Status: Downloaded newer image for postgres:latest Pulling grafana (kamon/grafana_graphite:latest)... latest: Pulling from kamon/grafana_graphite Status: Downloaded newer image for kamon/grafana_graphite:latest
Creating animal_grafana_1 Creating animal_postgres_1
ERROR: for postgres Cannot start service postgres: driver failed programming external connectivity on endpoint animal_postgres_1 (74e6a313523f26cd8ae95d056ee3183dd987696bfd14afbd1b32b758b966a86e): Error starting userland proxy: listen tcp 0.0.0.0:5432: bind: address already in use ERROR: Encountered errors while bringing up the project.

Do I need change the port? or how to fix that?
thanks for your help!
carlos

ps.
this is my docker compose:
version: '2' services: postgres: image: postgres ports: - 5432:5432 environment: POSTGRES_DB: animal_dev POSTGRES_USER: animal POSTGRES_PASSWORD: animal grafana: image: kamon/grafana_graphite logging: options: max-size: "100k" max-file: "20" ports: - 11080:80 - 11081:81 - 18125:18125/udp - 18126:18126


#2

Hi,
do you use postgres image in the containerInfo part of your circle.yml file ?
If true, that might be this postgres instance already running and preventing the one from your compose file to run.
In our compose file, do you need 5432 exposes to the outside or just restricted to your application (using exposes instead of port).
Luc


#3

hello @lucj! thanks for the answer

No in the containerinfo I just have the running container to build the image and no postgres. :frowning:


#4

Hi,

just out of curiosity, do you need to export the port

ports:

  • 5432:5432

rather than only exposing it to the rest of your compose application ?

expose:

  • 5432

Thanks,
Luc


#5

Thanks @lucj

Now the docker-compose rans ok, howerver I’m not able to access that :confused:


#6

Hi @cpanato,
sorry what do you mean by you cannot access ?
Do you try to access your compose application on port 11080 ?
My understanding is (I might be wrong though) that compose can be used to test a multi service (containers) applications. But you cannot run a compose application and expect it to be accessible from the outside as if it were running on a dedicated Docker host. For me, the application is within CircleCI test pipeline.
Anyone have any feedback on that ?
thanks a lot,
Luc


#7

@lucj I will try this port, but why this port?

thanks again!


#8

@cpanato
no, it was just a question as I see this port is mapped on grafana port 80 and though you tried to access the application that way.
What do you mean by " I’m not able to access that" ?


#9

@lucj
This is the steps I’m doing:

  1. run docker-compose
    docker-compose up -d

  2. run the docker image I just build and try to attach the postgres
    docker run --rm=false -t --add-host=hostip:``ip -4 addr show scope global dev eth0 | grep inet | awk '{print \$2}' | cut -d / -f 1`` ${DOCKER_REPO}/${NAME}:latest /bin/bash -c "MIX_ENV=test DB_HOST=hostip mix test"


#10

@cpanato,

From what I understand, you want to add the ip of the current circleci host in the etc/hosts of your container first.
There is a couple of things I’m not sure about:

  • the syntax to add the host in the local dns (/etc/hosts) but I’ll do something like:
    ip=$( ip -4 addr show scope global dev eth0 | grep inet | awk ‘{print $2}’ | cut -d / -f 1) first and then use $ip if this is what you need.
    docker run --rm=false -t --add-host=hostip:ip {DOCKER_REPO}/${NAME}:latest /bin/bash -c “MIX_ENV=test DB_HOST=hostip mix test”

  • when running a compose application, there is a default network that is created for the container to communicate. If you run another container from outside compose,you need to tell it to join this network as well (–net option). Otherwise you can export the port of the db and connect to it right away (maybe you could map the default port 5432 to something else as it seems from the original question that this one was already taken).

Otherwise, I think you should create another service in your compose file that is dedicated to test the other ones and which you could trigger like: docker-compose run mytestservice. As this one is part of the compose stack, it will have access to the other services without having to “plug” an external container to our application. Does it make sense ?

Luc


#11

@lucj
thanks!!
I will try out those


#12

@cpanato please let me know how it goes.
Luc


#13

What I did

I saw when we install the docker engine we need to run one step: ` - type: setup-docker-engine``

and the output for this is these environment variables:
Allocating a remote Docker Engine ............ Remote Docker engine created Created container accessible with: DOCKER_TLS_VERIFY=1 DOCKER_HOST=tcp://104.196.137.194:2376 DOCKER_CERT_PATH=/tmp/docker-certs284158524 DOCKER_MACHINE_NAME=311

The we tried to use this DOCKER_HOST when add the host in the docker run
echo $DOCKER_HOST export DHOST=echo $DOCKER_HOST | cut -d: -f 2 | cut -d’/’ -f 3echo $DHOST docker run --rm=false -t --add-host=hostip:$DHOST ${DOCKER_REPO}/${NAME}:latest /bin/bash -c "cat /etc/hosts && MIX_ENV=test DB_HOST=hostip mix test"

but also the same error :worried:

My understanding is when we setup the docker engine and ran that step it provide an remote docker and all the stuffs are there, including the images we run if docker-compose and docker run, right ? or not.

maybe we need someone from Circle ci to explain if I can do that or not.

thanks


#14

Please DM us your build details.


#15

@anon30319619 how to DM?


#16

I’m running into this same situation, with both the executorType of “docker” and “machine” - which is odd because the docs describe the machine type as being very bare.

Why is port 5432 being taken up on the host? Can we shutdown the service (postgres) that’s stealing this port? Sure I can work around this, but this is a hassle, and I would imagine quite a common situation.


#17

You can not connect directly to a container if you run it from executorType: docker, but you can run multiple containers that can connect to each other. Instead, just specify the image using that executorType and connect to it. Or shut down the postgres service manually, but that is the slowest method.


#18

Ok, I needed some other networking stuff / compose / etc anyway, so went for the machine type.

I just ran:
sudo service postgresql stop

To shut down postgres first. To me it seems surprising that a bare machine instance like this would start mysql and postgresql by default. Anyway, it works now. Thanks for the help.


#19

When you docker-compose up in executorType: docker, as long as those containers are on the same network, they will connect. It may not work for you use case, but I wanted to note that.


#20