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: Connection, Container, Event, Image, Messages

Constant Summary collapse

VERSION =

The version of the docker-api gem.

'1.7.5'
API_VERSION =

The version of the compatible Docker remote API.

'1.6'

Class Method Summary collapse

Class Method Details

.authenticate!(options = {}) ⇒ Object

Login to the Docker registry.



60
61
62
63
64
65
66
67
# File 'lib/docker.rb', line 60

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



41
42
43
# File 'lib/docker.rb', line 41

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



15
16
17
# File 'lib/docker.rb', line 15

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

.env_urlObject



19
20
21
# File 'lib/docker.rb', line 19

def env_url
  ENV['DOCKER_URL']
end

.infoObject

Get more information about the Docker server.



55
56
57
# File 'lib/docker.rb', line 55

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

.optionsObject



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

def options
  @options ||= {}
end

.options=(new_options) ⇒ Object



36
37
38
39
# File 'lib/docker.rb', line 36

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

.reset_connection!Object



45
46
47
# File 'lib/docker.rb', line 45

def reset_connection!
  @connection = nil
end

.urlObject



23
24
25
# File 'lib/docker.rb', line 23

def url
  @url ||= ENV['DOCKER_URL'] || default_socket_url
end

.url=(new_url) ⇒ Object



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

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.



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

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.



50
51
52
# File 'lib/docker.rb', line 50

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