Class: DockerSwarm::Container

Inherits:
Base
  • Object
show all
Includes:
DockerSwarm::Concerns::Creatable, DockerSwarm::Concerns::Deletable, DockerSwarm::Concerns::Loggable
Defined in:
lib/docker_swarm/models/container.rb

Overview

Represents a Docker Container

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DockerSwarm::Concerns::Loggable

#logs

Methods included from DockerSwarm::Concerns::Deletable

#destroy

Methods included from DockerSwarm::Concerns::Creatable

#query_params_for_docker, #save

Methods inherited from Base

all, #as_json, #assign_attributes, #attributes, defined_attributes, find, #id, #initialize, #method_missing, #payload_for_docker, #persisted?, #reload, resource_name, #respond_to_missing?, root_key, routes, #serializable_hash, where

Methods included from DockerSwarm::Concerns::Inspectable

#inspect

Constructor Details

This class inherits a constructor from DockerSwarm::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class DockerSwarm::Base

Class Method Details

.create_query_paramsArray<String>

POST /containers/create toma el nombre por query string. En el body Docker lo descarta en silencio y responde 201: el container nace con nombre aleatorio y la adopción por nombre determinista en un reintento no encuentra nada, así que el reintento duplica. Ver ADR-025 cláusula 1.

Returns:

  • (Array<String>)


16
17
18
# File 'lib/docker_swarm/models/container.rb', line 16

def self.create_query_params
  %w[name].freeze
end

.index_query_paramsArray<Symbol>

GET /containers/json declara exactamente tres query params propios además de filters: all, limit y size (spec v1.41, ContainerList).

No hereda el default de Base porque since y before son filtros de este recurso, no query params: ruteados a la URL el Engine los ignora y devuelve la lista sin filtrar, sin error — resultado incorrecto silencioso, peor que el rechazo ruidoso de #22. Y size faltaba: es query param propio (pide el tamaño de los archivos del container), así que viajaba dentro de filters como filtro inválido. Ver #35.

Returns:

  • (Array<Symbol>)

    Symbols (matchean contra las claves de filters)



31
32
33
# File 'lib/docker_swarm/models/container.rb', line 31

def self.index_query_params
  %i[all limit size].freeze
end

Instance Method Details

#startBoolean

Starts the container

Returns:

  • (Boolean)

    true if successful



37
38
39
40
# File 'lib/docker_swarm/models/container.rb', line 37

def start
  Api.request(action: self.class.routes[:start], arguments: { id: self.ID })
  true
end

#stopBoolean

Stops the container

Returns:

  • (Boolean)

    true if successful



44
45
46
47
# File 'lib/docker_swarm/models/container.rb', line 44

def stop
  Api.request(action: self.class.routes[:stop], arguments: { id: self.ID })
  true
end