Module: Docker

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

Overview

The top-level module for this gem. Its 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.

'2.3.0'

Class Method Summary collapse

Class Method Details

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

Login to the Docker registry.



133
134
135
136
137
138
139
140
# File 'lib/docker.rb', line 133

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

.connectionObject



93
94
95
# File 'lib/docker.rb', line 93

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

.credsObject

Returns the value of attribute creds.



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

def creds
  @creds
end

.creds=(value) ⇒ Object

Sets the attribute creds

Parameters:

  • value

    the value to set the attribute creds to.



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

def creds=(value)
  @creds = value
end

.default_socket_urlObject



39
40
41
# File 'lib/docker.rb', line 39

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

.env_optionsObject



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

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



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

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

.info(connection = self.connection) ⇒ Object

Get more information about the Docker server.



113
114
115
# File 'lib/docker.rb', line 113

def info(connection = self.connection)
  connection.info
end

.loggerObject

Returns the value of attribute logger.



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

def logger
  @logger
end

.logger=(value) ⇒ Object

Sets the attribute logger

Parameters:

  • value

    the value to set the attribute logger to.



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

def logger=(value)
  @logger = value
end

.optionsObject



79
80
81
# File 'lib/docker.rb', line 79

def options
  @options ||= env_options
end

.options=(new_options) ⇒ Object



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

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

.ping(connection = self.connection) ⇒ Object

Ping the Docker server.



118
119
120
# File 'lib/docker.rb', line 118

def ping(connection = self.connection)
  connection.ping
end

.podman?(connection = self.connection) ⇒ Boolean

Determine if the server is podman or docker.

Returns:

  • (Boolean)


123
124
125
# File 'lib/docker.rb', line 123

def podman?(connection = self.connection)
  connection.podman?
end

.reset!Object



97
98
99
100
101
# File 'lib/docker.rb', line 97

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

.reset_connection!Object



103
104
105
# File 'lib/docker.rb', line 103

def reset_connection!
  @connection = nil
end

.rootless?(connection = self.connection) ⇒ Boolean

Determine if the session is rootless.

Returns:

  • (Boolean)


128
129
130
# File 'lib/docker.rb', line 128

def rootless?(connection = self.connection)
  connection.rootless?
end

.ssl_optionsObject



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

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

.urlObject



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

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



83
84
85
86
# File 'lib/docker.rb', line 83

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

.version(connection = self.connection) ⇒ Object

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



108
109
110
# File 'lib/docker.rb', line 108

def version(connection = self.connection)
  connection.version
end