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: Base, Error, Util Classes: Connection, Container, Event, Exec, Image, ImageTask, Messages, MessagesStack, Network, Volume

Constant Summary collapse

VERSION =

The version of the docker-api gem.

'1.29.0'
API_VERSION =

The version of the compatible Docker remote API.

'1.16'

Class Method Summary collapse

Class Method Details

.authenticate!(options = {}, connection = self.connection) ⇒ Object

Login to the Docker registry.



121
122
123
124
125
126
127
128
# File 'lib/docker.rb', line 121

def authenticate!(options = {}, connection = self.connection)
  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



91
92
93
# File 'lib/docker.rb', line 91

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

.credsObject

Returns the value of attribute creds.



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

def creds
  @creds
end

.creds=(value) ⇒ Object

Sets the attribute creds

Parameters:

  • value

    the value to set the attribute creds to.



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

def creds=(value)
  @creds = value
end

.default_socket_urlObject



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

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

.env_optionsObject



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/docker.rb', line 45

def env_options
  if cert_path = ENV['DOCKER_CERT_PATH']
    {
      client_cert: File.join(cert_path, 'cert.pem'),
      client_key: File.join(cert_path, 'key.pem'),
      ssl_ca_file: File.join(cert_path, 'ca.pem'),
      scheme: 'https'
    }.merge(ssl_options)
  else
    {}
  end
end

.env_urlObject



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

def env_url
  ENV['DOCKER_URL'] || ENV['DOCKER_HOST']
end

.info(connection = self.connection) ⇒ Object

Get more information about the Docker server.



111
112
113
# File 'lib/docker.rb', line 111

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

.loggerObject

Returns the value of attribute logger.



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

def logger
  @logger
end

.logger=(value) ⇒ Object

Sets the attribute logger

Parameters:

  • value

    the value to set the attribute logger to.



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

def logger=(value)
  @logger = value
end

.optionsObject



77
78
79
# File 'lib/docker.rb', line 77

def options
  @options ||= env_options
end

.options=(new_options) ⇒ Object



86
87
88
89
# File 'lib/docker.rb', line 86

def options=(new_options)
  @options = env_options.merge(new_options || {})
  reset_connection!
end

.ping(connection = self.connection) ⇒ Object

Ping the Docker server.



116
117
118
# File 'lib/docker.rb', line 116

def ping(connection = self.connection)
  connection.get('/_ping')
end

.reset!Object



95
96
97
98
99
# File 'lib/docker.rb', line 95

def reset!
  @url = nil
  @options = nil
  reset_connection!
end

.reset_connection!Object



101
102
103
# File 'lib/docker.rb', line 101

def reset_connection!
  @connection = nil
end

.ssl_optionsObject



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

def ssl_options
  if ENV['DOCKER_SSL_VERIFY'] == 'false'
    {
      ssl_verify_peer: false
    }
  else
    {}
  end
end

.urlObject



68
69
70
71
72
73
74
75
# File 'lib/docker.rb', line 68

def url
  @url ||= env_url || default_socket_url
  # docker uses a default notation tcp:// which means tcp://localhost:2375
  if @url == 'tcp://'
    @url = 'tcp://localhost:2375'
  end
  @url
end

.url=(new_url) ⇒ Object



81
82
83
84
# File 'lib/docker.rb', line 81

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.



132
133
134
135
136
137
# File 'lib/docker.rb', line 132

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

.version(connection = self.connection) ⇒ Object

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



106
107
108
# File 'lib/docker.rb', line 106

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