Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker link to previously started containers

I'd like to carry out a one shot docker-compose run that will run against some previously started containers. My docker-compose.yml file will look like this:

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

My workflow is:

  1. Start the long running service docker-compose up long_running_service
  2. Run the one shot service multiple times. docker-compose run --no-deps one_shot_service

When I do this the /etc/hosts file on the one_shot_service does not contain an entry for docker. When I run without --no-deps it's fine. The reason I don't want to run without no-deps is beause the long_running_service takes a long time to start up.

So long story short, how can I link to existing containers?

like image 930
Oliver Shaw Avatar asked Nov 03 '15 13:11

Oliver Shaw


People also ask

What is the command line option getting used to link two containers?

For an easy solution you could use Docker-compose . in you compose file (docker-compose. yml) use the option links Link to containers in another service. Either specify both the service name and a link alias (SERVICE:ALIAS), or just the service name.

What is link container?

Container Linking allows multiple containers to link with each other. It is a better option than exposing ports.


1 Answers

You can use the external_links directive.

Example:

external_links:
    - long_running_service:your_alias
like image 170
Chris McKinnel Avatar answered Oct 05 '22 12:10

Chris McKinnel