Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker-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?
like image 710
Mihnea DB Avatar asked Apr 06 '15 15:04

Mihnea DB


People also ask

Is docker compose links deprecated?

According to the Docker docs, links are described as “legacy”. In particular, there's this warning: Warning: The --link flag is a deprecated legacy feature of Docker.

What does links do docker compose?

links instructs Docker to link containers over a network. When we link containers, Docker creates environment variables and adds containers to the known hosts list so they can discover each other.

Can docker compose run commands?

Docker Compose allows us to execute commands inside a Docker container. During the container startup, we can set any command via the command instruction. In the above docker-compose. yml file, we are executing a single echo command inside the alpine Docker image.


2 Answers

My take on the answers:

  1. It's a bug.
  2. See if it's fixed in an unreleased version of docker-compose or create an issue asking that the bug be fixed.
like image 77
Nathan Stocks Avatar answered Oct 03 '22 08:10

Nathan Stocks


I only have an answer for the question number 2. Start the whole environment using docker-compose run and then execute docker exec in the analytics container

docker exec -ti $analytics_container_id bash
like image 20
Javier Segura Avatar answered Oct 03 '22 06:10

Javier Segura