Module: Docker

Defined in:
lib/docker.rb,
lib/docker/version.rb

Overview

The top-level module for this gem. It’s purpose is to hold global configuration variables that are used as defaults in other classes.

Defined Under Namespace

Modules: Error, Util Classes: Base, Connection, Container, Event, Image, ImageTask, Messages

Constant Summary collapse

VERSION =

The version of the docker-api gem.

'1.9.1'
API_VERSION =

The version of the compatible Docker remote API.

'1.9'

Class Method Summary collapse

Class Method Details

.authenticate!(options = {}) ⇒ Object

Login to the Docker registry.



76
77
78
79
80
81
82
83
# File 'lib/docker.rb', line 76

def authenticate!(options = {})
  creds = options.to_json
  connection.post('/auth', {}, :body => creds)
  @creds = creds
  true
rescue Docker::Error::ServerError, Docker::Error::UnauthorizedError
  raise Docker::Error::AuthenticationError
end

.connectionObject



57
58
59
# File 'lib/docker.rb', line 57

def connection
  @connection ||= Connection.new(url, options)
end

.credsObject

Returns the value of attribute creds.



13
14
15
# File 'lib/docker.rb', line 13

def creds
  @creds
end

.creds=(value) ⇒ Object

Sets the attribute creds

Parameters:

  • value

    the value to set the attribute creds to.



13
14
15
# File 'lib/docker.rb', line 13

def creds=(value)
  @creds = value
end

.default_socket_urlObject



26
27
28
# File 'lib/docker.rb', line 26

def default_socket_url
  'unix:///var/run/docker.sock'
end

.env_urlObject



30
31
32
# File 'lib/docker.rb', line 30

def env_url
  ENV['DOCKER_URL']
end

.infoObject

Get more information about the Docker server.



71
72
73
# File 'lib/docker.rb', line 71

def info
  Util.parse_json(connection.get('/info'))
end

.loggerObject

Returns the value of attribute logger.



13
14
15
# File 'lib/docker.rb', line 13

def logger
  @logger
end

.logger=(value) ⇒ Object

Sets the attribute logger

Parameters:

  • value

    the value to set the attribute logger to.



13
14
15
# File 'lib/docker.rb', line 13

def logger=(value)
  @logger = value
end

.optionsObject



43
44
45
# File 'lib/docker.rb', line 43

def options
  @options ||= {}
end

.options=(new_options) ⇒ Object



52
53
54
55
# File 'lib/docker.rb', line 52

def options=(new_options)
  @options = new_options
  reset_connection!
end

.reset_connection!Object



61
62
63
# File 'lib/docker.rb', line 61

def reset_connection!
  @connection = nil
end

.urlObject



34
35
36
37
38
39
40
41
# File 'lib/docker.rb', line 34

def url
  @url ||= ENV['DOCKER_URL'] || ENV['DOCKER_HOST'] || default_socket_url
  # docker uses a default notation tcp:// which means tcp://localhost:4243
  if @url == 'tcp://'
    @url = 'tcp://localhost:4243'
  end
  @url
end

.url=(new_url) ⇒ Object



47
48
49
50
# File 'lib/docker.rb', line 47

def url=(new_url)
  @url = new_url
  reset_connection!
end

.validate_version!Object

When the correct version of Docker is installed, returns true. Otherwise, raises a VersionError.



87
88
89
90
91
92
# File 'lib/docker.rb', line 87

def validate_version!
  Docker.info
  true
rescue Docker::Error::DockerError
  raise Docker::Error::VersionError, "Expected API Version: #{API_VERSION}"
end

.versionObject

Get the version of Go, Docker, and optionally the Git commit.



66
67
68
# File 'lib/docker.rb', line 66

def version
  Util.parse_json(connection.get('/version'))
end