Method: Docker::Compose::Mapper#host_and_port

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

#host_and_port(service, port) ⇒ Array

Figure out which host port a given service’s port has been published to, and/or whether that service is running. Cannot distinguish between the “service not running” case and the “container port not published” case!

Returns:

  • (Array)

    (String, Integer) pair of host address and port number

Raises:

  • (NoService)

    if service is not up or does not publish port


102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/docker/compose/mapper.rb', line 102

def host_and_port(service, port)
  result = @session.port(service, port.to_s)
  if result
    result.chomp!
  else
    raise NoService,
          "Service '#{service}' not running, or does not " \
          "publish port '#{port}'"
  end

  host, port = result.split(':')
  host = @override_host if @override_host

  [host, Integer(port)]
end