Class: Docker::API::Service

Inherits:
Base
  • Object
show all
Defined in:
lib/docker/api/service.rb

Overview

This class represents the Docker API endpoints regarding services.

Services are the definitions of tasks to run on a swarm. Swarm mode must be enabled for these endpoints to work.

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Docker::API::Base

Instance Method Details

#create(body = {}, authentication = {}) ⇒ Object

Create a service

Docker API: POST /services/create

Parameters:

  • body (Hash) (defaults to: {})

    : Request body to be sent as json.

  • authentication (Hash) (defaults to: {})

    : Authentication parameters.

See Also:



24
25
26
27
28
# File 'lib/docker/api/service.rb', line 24

def create body = {}, authentication = {}
    headers = {"Content-Type": "application/json"}
    headers.merge!({"X-Registry-Auth" => auth_encoder(authentication) }) if authentication.keys.size > 0
    @connection.request(method: :post, path: "/services/create", headers: headers, body: body.to_json)
end

#delete(name) ⇒ Object

Delete a service

Docker API: DELETE /services/id

Parameters:

  • name (String)

    : The ID or name of the service.

See Also:



74
75
76
# File 'lib/docker/api/service.rb', line 74

def delete name
    @connection.delete("/services/#{name}")
end

#details(name, params = {}) ⇒ Object

Inspect a service

Docker API: GET /services/id

Parameters:

  • name (String)

    : The ID or name of the service.

  • params (Hash) (defaults to: {})

    : Parameters that are appended to the URL.

See Also:



53
54
55
# File 'lib/docker/api/service.rb', line 53

def details name, params = {}
    @connection.get(build_path("/services/#{name}", params))
end

#list(params = {}) ⇒ Object

List services

Docker API: GET /services

Parameters:

  • params (Hash) (defaults to: {})

    : Parameters that are appended to the URL.

See Also:



13
14
15
# File 'lib/docker/api/service.rb', line 13

def list params = {}
    @connection.get(build_path("/services", params))
end

#logs(name, params = {}) ⇒ Object

Get stdout and stderr logs from a service.

Docker API: GET /services/id/logs

Parameters:

  • name (String)

    : The ID or name of the service.

  • params (Hash) (defaults to: {})

    : Parameters that are appended to the URL.

See Also:



64
65
66
# File 'lib/docker/api/service.rb', line 64

def logs name, params = {}
    @connection.get(build_path("/services/#{name}/logs", params))
end

#update(name, params = {}, body = {}, authentication = {}) ⇒ Object

Update a service

Docker API: POST /services/id/update

Parameters:

  • name (String)

    : The ID or name of the service.

  • params (Hash) (defaults to: {})

    : Parameters that are appended to the URL.

  • body (Hash) (defaults to: {})

    : Request body to be sent as json.

  • authentication (Hash) (defaults to: {})

    : Authentication parameters.

See Also:



39
40
41
42
43
44
# File 'lib/docker/api/service.rb', line 39

def update name, params = {}, body = {}, authentication = {}
    # view https://github.com/docker/swarmkit/issues/1394#issuecomment-240850719
    headers = {"Content-Type": "application/json"}
    headers.merge!({"X-Registry-Auth" => auth_encoder(authentication) }) if authentication.keys.size > 0
    @connection.request(method: :post, path: build_path("/services/#{name}/update", params), headers: headers, body: body.to_json)
end