Method: Docker::Compose::Mapper#map

Defined in:
lib/docker/compose/mapper.rb

#map(value) ⇒ String, Array

Substitute service hostnames and ports that appear in a URL or a host:port string. If either component of a host:port string is surrounded by square brackets, “elide” that component, removing it from the result but using it to find the correct service and port.

Examples:

map MySQL on local docker host with 3306 published to 13847

map("tcp://db:3306") # => "tcp://127.0.0.1:13847"

map just the hostname of MySQL on local docker host

map("db:[3306]") # => "127.0.0.1"

map just the port of MySQL on local docker host

map("[db]:3306") # => "13847"

map an array of database hosts

map(["[db1]:3306", "[db2]:3306"])

Parameters:

  • value (String, #map)

    a URI, host:port pair, or an array of either

Returns:

  • (String, Array)

    the mapped value with container-names and ports substituted

Raises:

  • (BadSubstitution)

    if a substitution string can’t be parsed

  • (NoService)

    if service is not up or does not publish port

[View source]

88
89
90
91
92
93
94
# File 'lib/docker/compose/mapper.rb', line 88

def map(value)
  if value.respond_to?(:map)
    value.map { |e| map_scalar(e) }
  else
    map_scalar(value)
  end
end