compose: `run` does not set links

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

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 26

Most upvoted comments

@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

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.

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.