A helper to fetch dynamically allocated ports with Docker Compose.
Add the following to your Gemfile
gem 'compose', git: 'https://github.com/kickstarter/compose'Fetch the currently allocated port for a service:
Compose.port(:redis, 6379)
# => 49811Fetch the port and interpolate it into a template string:
Compose.port(:redis, 6379, 'redis://localhost:%s/')
# => "redis://localhost:49811/"Use in a Rails config YAML file:
# ./config/redis.yml
---
development:
host: localhost
port: <%= Config.port(:redis, 6379) %>
url: <%= Config.port(:redis, 6379, 'redis://localhost:%s/') %>