Docker link to previously loaded containers

I would like to fire one shot of docker-compose run , which will work against some previously launched containers. My docker-compose.yml file will look like this:

 one_shot_service: ... links: - long_running_service:docker long_running_service: ... 

My workflow:

  • Launch docker-compose up long_running_service long-term service
  • Start the one-time service several times. docker-compose run --no-deps one_shot_service

When I do this, the /etc/hosts on one_shot_service does not contain a one_shot_service entry. When I run without --no-deps , this is normal. The reason I don't want to start without no-deps is because long_running_service takes a lot of time to start.

In short, how can I link existing containers?

+8
docker docker-compose
source share
1 answer

You can use the external_links directive.

Example:

 external_links: - long_running_service:your_alias 
+9
source share

All Articles