module Docker

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

Constants

VERSION

The version of the docker-api gem.

Attributes

creds[RW]
logger[RW]
creds[RW]
logger[RW]

Public Class Methods

authenticate!(options = {}, connection = self.connection) click to toggle source

Login to the Docker registry.

# File lib/docker.rb, line 135
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
connection() click to toggle source
# File lib/docker.rb, line 95
def connection
  @connection ||= Connection.new(url, options)
end
default_socket_url() click to toggle source
# File lib/docker.rb, line 41
def default_socket_url
  'unix:///var/run/docker.sock'
end
env_options() click to toggle source
# File lib/docker.rb, line 49
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_url() click to toggle source
# File lib/docker.rb, line 45
def env_url
  ENV['DOCKER_URL'] || ENV['DOCKER_HOST']
end
info(connection = self.connection) click to toggle source

Get more information about the Docker server.

# File lib/docker.rb, line 115
def info(connection = self.connection)
  connection.info
end
options() click to toggle source
# File lib/docker.rb, line 81
def options
  @options ||= env_options
end
options=(new_options) click to toggle source
# File lib/docker.rb, line 90
def options=(new_options)
  @options = env_options.merge(new_options || {})
  reset_connection!
end
ping(connection = self.connection) click to toggle source

Ping the Docker server.

# File lib/docker.rb, line 120
def ping(connection = self.connection)
  connection.ping
end
podman?(connection = self.connection) click to toggle source

Determine if the server is podman or docker.

# File lib/docker.rb, line 125
def podman?(connection = self.connection)
  connection.podman?
end
reset!() click to toggle source
# File lib/docker.rb, line 99
def reset!
  @url = nil
  @options = nil
  reset_connection!
end
reset_connection!() click to toggle source
# File lib/docker.rb, line 105
def reset_connection!
  @connection = nil
end
rootless?(connection = self.connection) click to toggle source

Determine if the session is rootless.

# File lib/docker.rb, line 130
def rootless?(connection = self.connection)
  connection.rootless?
end
ssl_options() click to toggle source
# File lib/docker.rb, line 62
def ssl_options
  if ENV['DOCKER_SSL_VERIFY'] == 'false'
    {
      ssl_verify_peer: false
    }
  else
    {}
  end
end
url() click to toggle source
# File lib/docker.rb, line 72
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) click to toggle source
# File lib/docker.rb, line 85
def url=(new_url)
  @url = new_url
  reset_connection!
end
version(connection = self.connection) click to toggle source

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

# File lib/docker.rb, line 110
def version(connection = self.connection)
  connection.version
end

Private Instance Methods

authenticate!(options = {}, connection = self.connection) click to toggle source

Login to the Docker registry.

# File lib/docker.rb, line 135
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
connection() click to toggle source
# File lib/docker.rb, line 95
def connection
  @connection ||= Connection.new(url, options)
end
default_socket_url() click to toggle source
# File lib/docker.rb, line 41
def default_socket_url
  'unix:///var/run/docker.sock'
end
env_options() click to toggle source
# File lib/docker.rb, line 49
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_url() click to toggle source
# File lib/docker.rb, line 45
def env_url
  ENV['DOCKER_URL'] || ENV['DOCKER_HOST']
end
info(connection = self.connection) click to toggle source

Get more information about the Docker server.

# File lib/docker.rb, line 115
def info(connection = self.connection)
  connection.info
end
options() click to toggle source
# File lib/docker.rb, line 81
def options
  @options ||= env_options
end
options=(new_options) click to toggle source
# File lib/docker.rb, line 90
def options=(new_options)
  @options = env_options.merge(new_options || {})
  reset_connection!
end
ping(connection = self.connection) click to toggle source

Ping the Docker server.

# File lib/docker.rb, line 120
def ping(connection = self.connection)
  connection.ping
end
podman?(connection = self.connection) click to toggle source

Determine if the server is podman or docker.

# File lib/docker.rb, line 125
def podman?(connection = self.connection)
  connection.podman?
end
reset!() click to toggle source
# File lib/docker.rb, line 99
def reset!
  @url = nil
  @options = nil
  reset_connection!
end
reset_connection!() click to toggle source
# File lib/docker.rb, line 105
def reset_connection!
  @connection = nil
end
rootless?(connection = self.connection) click to toggle source

Determine if the session is rootless.

# File lib/docker.rb, line 130
def rootless?(connection = self.connection)
  connection.rootless?
end
ssl_options() click to toggle source
# File lib/docker.rb, line 62
def ssl_options
  if ENV['DOCKER_SSL_VERIFY'] == 'false'
    {
      ssl_verify_peer: false
    }
  else
    {}
  end
end
url() click to toggle source
# File lib/docker.rb, line 72
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) click to toggle source
# File lib/docker.rb, line 85
def url=(new_url)
  @url = new_url
  reset_connection!
end
version(connection = self.connection) click to toggle source

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

# File lib/docker.rb, line 110
def version(connection = self.connection)
  connection.version
end