Class: Docker::API::Network

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

Overview

This class represents the Docker API endpoints regarding networks.

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

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

Instance Method Details

#connect(name, body = {}) ⇒ Object

Connect a container to a network.

Docker API: POST /networks/id/connect

Parameters:

  • name (String)

    : The ID or name of the network.

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

    : Request body to be sent as json.

See Also:



70
71
72
# File 'lib/docker/api/network.rb', line 70

def connect name, body = {}
    @connection.request(method: :post, path: "/networks/#{name}/connect", headers: {"Content-Type": "application/json"}, body: body.to_json)
end

#create(body = {}) ⇒ Object

Create a network.

Docker API: POST /networks/create

Parameters:

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

    : Request body to be sent as json.

See Also:



36
37
38
# File 'lib/docker/api/network.rb', line 36

def create body = {}
    @connection.request(method: :post, path: "/networks/create", headers: {"Content-Type": "application/json"}, body: body.to_json)
end

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

Inspect a network.

Docker API: GET /networks/id

Parameters:

  • name (String)

    : The ID or name of the network.

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

    : Parameters that are appended to the URL.

See Also:



25
26
27
# File 'lib/docker/api/network.rb', line 25

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

#disconnect(name, body = {}) ⇒ Object

Disconnect a container from a network.

Docker API: POST /networks/id/disconnect

Parameters:

  • name (String)

    : The ID or name of the network.

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

    : Request body to be sent as json.

See Also:



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

def disconnect name, body = {}
    @connection.request(method: :post, path: "/networks/#{name}/disconnect", headers: {"Content-Type": "application/json"}, body: body.to_json)
end

#list(params = {}) ⇒ Object

List networks.

Docker API: GET /networks

Parameters:

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

    : Parameters that are appended to the URL.

See Also:



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

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

#prune(params = {}) ⇒ Object

Delete unused networks.

Docker API: POST /networks/prune

Parameters:

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

    : Parameters that are appended to the URL.

See Also:



58
59
60
# File 'lib/docker/api/network.rb', line 58

def prune params = {}
    @connection.post(build_path("/networks/prune", params))
end

#remove(name) ⇒ Object

Remove a network.

Docker API: DELETE /networks/id

Parameters:

  • name (String)

    : The ID or name of the network.

See Also:



47
48
49
# File 'lib/docker/api/network.rb', line 47

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