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
Constant Summary collapse
- VERSION =
The version of the docker-api gem.
'1.23.0'
- API_VERSION =
The version of the compatible Docker remote API.
'1.16'
Class Method Summary collapse
-
.authenticate!(options = {}, connection = self.connection) ⇒ Object
Login to the Docker registry.
- .connection ⇒ Object
-
.creds ⇒ Object
Returns the value of attribute creds.
-
.creds=(value) ⇒ Object
Sets the attribute creds.
- .default_socket_url ⇒ Object
- .env_options ⇒ Object
- .env_url ⇒ Object
-
.info(connection = self.connection) ⇒ Object
Get more information about the Docker server.
-
.logger ⇒ Object
Returns the value of attribute logger.
-
.logger=(value) ⇒ Object
Sets the attribute logger.
- .options ⇒ Object
- .options=(new_options) ⇒ Object
- .reset! ⇒ Object
- .reset_connection! ⇒ Object
- .ssl_options ⇒ Object
- .url ⇒ Object
- .url=(new_url) ⇒ Object
-
.validate_version! ⇒ Object
When the correct version of Docker is installed, returns true.
-
.version(connection = self.connection) ⇒ Object
Get the version of Go, Docker, and optionally the Git commit.
Class Method Details
.authenticate!(options = {}, connection = self.connection) ⇒ Object
Login to the Docker registry.
114 115 116 117 118 119 120 121 |
# File 'lib/docker.rb', line 114 def authenticate!( = {}, connection = self.connection) creds = .to_json connection.post('/auth', {}, :body => creds) @creds = creds true rescue Docker::Error::ServerError, Docker::Error::UnauthorizedError raise Docker::Error::AuthenticationError end |
.connection ⇒ Object
89 90 91 |
# File 'lib/docker.rb', line 89 def connection @connection ||= Connection.new(url, ) end |
.creds ⇒ Object
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
20 21 22 |
# File 'lib/docker.rb', line 20 def creds=(value) @creds = value end |
.default_socket_url ⇒ Object
35 36 37 |
# File 'lib/docker.rb', line 35 def default_socket_url 'unix:///var/run/docker.sock' end |
.env_options ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/docker.rb', line 43 def 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() else {} end end |
.env_url ⇒ Object
39 40 41 |
# File 'lib/docker.rb', line 39 def env_url ENV['DOCKER_URL'] || ENV['DOCKER_HOST'] end |
.info(connection = self.connection) ⇒ Object
Get more information about the Docker server.
109 110 111 |
# File 'lib/docker.rb', line 109 def info(connection = self.connection) Util.parse_json(connection.get('/info')) end |
.logger ⇒ Object
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
20 21 22 |
# File 'lib/docker.rb', line 20 def logger=(value) @logger = value end |
.options ⇒ Object
75 76 77 |
# File 'lib/docker.rb', line 75 def @options ||= end |
.options=(new_options) ⇒ Object
84 85 86 87 |
# File 'lib/docker.rb', line 84 def () @options = .merge( || {}) reset_connection! end |
.reset! ⇒ Object
93 94 95 96 97 |
# File 'lib/docker.rb', line 93 def reset! @url = nil @options = nil reset_connection! end |
.reset_connection! ⇒ Object
99 100 101 |
# File 'lib/docker.rb', line 99 def reset_connection! @connection = nil end |
.ssl_options ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/docker.rb', line 56 def if ENV['DOCKER_SSL_VERIFY'] == 'false' { ssl_verify_peer: false } else {} end end |
.url ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/docker.rb', line 66 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
79 80 81 82 |
# File 'lib/docker.rb', line 79 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.
125 126 127 128 129 130 |
# File 'lib/docker.rb', line 125 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.
104 105 106 |
# File 'lib/docker.rb', line 104 def version(connection = self.connection) Util.parse_json(connection.get('/version')) end |