Compose: `run` does not set links

Created on 10 Apr 2015  路  26Comments  路  Source: docker/compose

I have a docker-compose.yml file along the lines of:

analytics:
    build: .
    links:
    - mongo:mongo
    ports:
    - 80:80
mongo:
    build: docker_containers/mongo
    expose:
    - 27017

Running docker-compose up creates a link in /etc/hosts to the mongo service. However, running docker-compose run analytics bash does not create the link -- I checked the /etc/hosts file.

The docs of docker-compose do not mention anything about this, so I'm confused.

  1. Why isn't the link set when using run?
  2. How can I achieve this?

original SO question

arerun kinbug

Most helpful comment

@stcalica Use fenced code blocks (```) to format your code. For example:

version: '2'
services:
  web:
    build: .
    volumes:
      - .:/usr/app/src
    command: python /usr/app/src/dashboard/runserver.py
    ports:
      - "5000:5000"
    links:
      - postgres
      - rabbitmq
  postgres:
    image: postgres
  rabbitmq:
    image: rabbitmq

All 26 comments

This can happen if your mongo container has died before the analytics container has started. Is it still running? You can check with docker-compose ps.

It is still running, yes. For the record, my workaround is to start the
mongo container with docker-compose run -d mongo and then do
docker-compose run analytics <...>.

On Tue, Apr 14, 2015 at 4:31 PM, Aanand Prasad [email protected]
wrote:

This can happen if your mongo container has died before the analytics
container has started. Is it still running? You can check with docker-compose
ps.

Reply to this email directly or view it on GitHub
https://github.com/docker/compose/issues/1276#issuecomment-92837025.

Mihnea Dobrescu-Balaur

I have the same issue, there is some solution?
Thanks!

Ok, sorry, forget it, It works, was a bad config in my app pointing to localhost instead of hostname of the link...
Thanks.

The same here. I have a nodejs container who tries to access a redis container, and I receive the folowing: Error: Redis connection to redis:6379 failed - connect EHOSTUNREACH
But sending a ping via redis-cli, I receive PONG.

We have run into the same issue when using docker-compose run. Our docker-compose.yml file specifies a link from our test_container to an "es" container for elasticsearch. docker-compose up works, but always returns 0 even if an error code was returned by the executing container. Upon further reading, it appears that is expected behavior, and one should use docker-compose run instead. Unfortunately, when doing this, it appears to ignore the links defined in the docker-compose.yml file, requiring one to first docker-compose run -d es, and then docker-compose run test_container. At this point, there is little value provided in using docker-compose vs. simply specifying the necessary docker commands to achieve the same thing. Is there any traction on a solution to this issue?

@magicclaw:

Unfortunately, when doing this, it appears to ignore the links defined in the docker-compose.yml file, requiring one to first docker-compose run -d es, and then docker-compose run test_container.

It should not be doing that - if test_container has a link to es, then docker-compose run test_container should start es first and link to it.

However, the link will not appear if es exits before test_container can start.

Can you produce a minimal example that showcases the problem?

I'm having the same problem. I have two containers, one linked to the second. If I try to start with docker-compose up, the links are not created. If I started first the container at the end of the link, then the container that links to it, everything works fine.

For reference, I'm running docker-compose 1.4, boot2docker 1.8, Windows 10 and cygwin.

+1

:+1: this is a blocking bug for us

I think you'll need to provide some more details about this error in order for us to debug what's happening.

Can you confirm the problem is not that the container being linked to is failing to start?

Closing this issue.

Additional details about the error were not provided and links are being deprecated and replaced with networks.

I have this issue too. I have MySQL, Selenium and Django test defined in my docker-compose.yml
If I start with docker-compose up test then the Selenium webdriver can connect to 'test:8081' however if I start with docker-compose run --publish 8081:8081 test then it cannot connect

You need to use --service-ports with --run I believe.

@dnephin That doesn't work either.

Having the same exact issue.
Python Flask app with Postgresql and Rabbitmq.

version: '2'
services:
web:
build: .
volumes:
- .:/usr/app/src
command: python /usr/app/src/dashboard/runserver.py
ports:
- "5000:5000"
links:
- postgres
- rabbitmq
postgres:
image: postgres
rabbitmq:
image: rabbitmq

My links are not being set up at all.

@stcalica Use fenced code blocks (```) to format your code. For example:

version: '2'
services:
  web:
    build: .
    volumes:
      - .:/usr/app/src
    command: python /usr/app/src/dashboard/runserver.py
    ports:
      - "5000:5000"
    links:
      - postgres
      - rabbitmq
  postgres:
    image: postgres
  rabbitmq:
    image: rabbitmq

Having the same exact issue.
Python Flask app with Postgresql and Rabbitmq.

version: '2'
services:
web:
build: .
volumes:
- .:/usr/app/src
command: python /usr/app/src/dashboard/runserver.py
ports:
- "5000:5000"
links:

    postgres
    rabbitmq postgres: image: postgres rabbitmq: image: rabbitmq

My links are not being set up at all.

I am using docker-compose version 1.6.2, build 4d72027 and I can definitely confirm that even with --service-ports container DNS resolution _does not_ work with docker-compose run <container> but _does_ work with docker-compose up <container>

I can get by using 'up' but it would be nice for the console output to be coloured as it is with 'run' (I am running BDD tests)

I'm happy to help test any suggestions.

EDIT: Just to make this clear; I can ping, connect etc. from the container I run to other containers but I cannot connect from the other containers to the one I run.

In my case I have Django, MySQL and Webdriver containers. If I use docker-compose up testserver which runs a Django test server and performs Webdriver tests then the 'webdriver' container can resolve the 'test' host. If I use docker-compose run testserver it cannot but the 'testserver' container can still resolve 'mysql' and 'webdriver' so it seems when using run the DNS is not being updated.

If all you need is colors, you can set tty: True on the service, which should allow the BDD output format to recognize that color is supported.

Containers created by run are not expected to be discoverable at the same name. They are considered "one-off" or "adhoc" containers for running a task.

This still look's like an issue to me. Please explain why it's closed if I did not understood something. Previously I had linked services for e.g. two Django apps and a Nginx one.
I opened three terminals and in order run:

#first term
$ docker-compose run --rm --no-deps app_1
#second term
$ docker-compose run --rm --no-deps app_2
#third term
$ docker-compose run --rm --no-deps --service-ports nginx

Nginx was configured to 'see' app_1 and app_2 by their service names. I can successfully ping project_app_run_1 but I simply don't want to.

Did you change this intentional? Or is it a bug? @dnephin you said that links are deprecated in favor of networks - how can I use networks to fix this?

P.S.
I can't use up which works fine with the exception that I can't use pbd with up.

Containers created by run are not expected to be discoverable as the service name. They are considered "one-off" or "adhoc" containers for running a task, not "regular service containers".

If you need to pdb, you can use docker attach I think.

Thank you. Overall it's a huge downfall of Compose for me. I'll have to figure out something else :(
attach doesn't work - can't input anything there.
Thanks again.

You may need to use stdin_open: True to input things (as well as tty: True).

Worked! Many thanks!

Was this page helpful?
0 / 5 - 0 ratings