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.
run
?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.
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.
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.
My take on the answers:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With