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:
docker-compose up long_running_service
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?
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.
Container Linking allows multiple containers to link with each other. It is a better option than exposing ports.
You can use the external_links directive.
Example:
external_links:
- long_running_service:your_alias
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