Class: Docker::Cli::DockerContainer

Inherits:
Object
  • Object
show all
Includes:
TR::CondUtils
Defined in:
lib/docker/cli/docker_container.rb

Overview

class NewContainerProfile

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, history = nil) ⇒ DockerContainer

Returns a new instance of DockerContainer.



128
129
130
131
# File 'lib/docker/cli/docker_container.rb', line 128

def initialize(name, history = nil)
  @name = name
  @history = history
end

Instance Attribute Details

#nameObject (readonly)

def self.container(name)

end



126
127
128
# File 'lib/docker/cli/docker_container.rb', line 126

def name
  @name
end

Class Method Details

.containers_of_image_from_history(img, opts = { }) ⇒ Object

# create non interactive session to create the user & group first

opts[:command] = "#{File.join(opts[:mount_docker],"create_user.sh")}"
opts[:detached] = true
command.create_container_from_image(image, opts).run

end



104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/docker/cli/docker_container.rb', line 104

def self.containers_of_image_from_history(img, opts = {  })
  cont = DockerRunLog.instance.containers(img)
  res = {}
  if cont.length == 1
    c = cont.first
    res[c[:container]] = c
  else
    cont.each do |c|
      res[c[:container]] = "#{c[:container]} [Last Access : #{Time.at(c[:last_run])}] - Config : #{c[:argv]}"
    end
    res
  end
end

Instance Method Details

#attach(&block) ⇒ Object



180
181
182
# File 'lib/docker/cli/docker_container.rb', line 180

def attach(&block)
  command.attach_container(@name).run
end

#create(container_profile) ⇒ Object

Raises:



139
140
141
142
143
144
# File 'lib/docker/cli/docker_container.rb', line 139

def create(container_profile)
  raise CommandFailed, " Image name is not given to create the container '#{@name}'" if is_empty?(container_profile.image_name)
  opts = container_profile.to_hash
  opts[:container_name] = @name
  command.create_container_from_image(container_profile.image_name, opts).run
end

#delete!(&block) ⇒ Object



184
185
186
# File 'lib/docker/cli/docker_container.rb', line 184

def delete!(&block)
  command.delete_container(@name).run
end

#historyObject



158
159
160
161
162
163
164
# File 'lib/docker/cli/docker_container.rb', line 158

def history
  if not @history.nil?
    @history.freeze
  else
    @history = {}
  end
end

#is_exist?Boolean

Returns:

  • (Boolean)

Raises:



133
134
135
136
137
# File 'lib/docker/cli/docker_container.rb', line 133

def is_exist?
  res = command.find_from_all_container(@name).run 
  raise CommandFailed, "Command to check if container exist failed. Error was : #{res.err_stream}" if not res.successful?
  not res.is_out_stream_empty?
end

#is_running?Boolean

Returns:

  • (Boolean)

Raises:



166
167
168
169
170
# File 'lib/docker/cli/docker_container.rb', line 166

def is_running?
  res = command.find_running_container(@name).run
  raise CommandFailed, "Command to find running container failed. Error was : #{res.err_stream}" if not res.successful?
  not res.is_out_stream_empty?
end

#name_for_displayObject



146
147
148
149
150
151
152
# File 'lib/docker/cli/docker_container.rb', line 146

def name_for_display
  if @history.nil?
    @name
  else
    "#{@history[:container]} [Last Access : #{Time.at(@history[:last_run])}] - Config : #{@history[:argv]}"
  end
end

#run(cmd, opts = {}, &block) ⇒ Object



188
189
190
# File 'lib/docker/cli/docker_container.rb', line 188

def run(cmd, opts = {}, &block)
  command.run_command_in_running_container(@name, cmd, opts).run 
end

#run_before?Boolean

Returns:

  • (Boolean)


154
155
156
# File 'lib/docker/cli/docker_container.rb', line 154

def run_before?
  not @history.nil?
end

#start(&block) ⇒ Object



172
173
174
# File 'lib/docker/cli/docker_container.rb', line 172

def start(&block)
  command.start_container(@name).run
end

#stop(&block) ⇒ Object



176
177
178
# File 'lib/docker/cli/docker_container.rb', line 176

def stop(&block)
  command.stop_container(@name).run
end