Method: Cnvrg::Images#get_container

Defined in:
lib/cnvrg/Images.rb

#get_container(stop = false) ⇒ Object



236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/cnvrg/Images.rb', line 236

def get_container(stop=false)
  begin
    container_id=is_container_exist()

    if !container_id
      return create_container()
    else
      container = Docker::Container.get(container_id)
      status = container.json["State"]["Status"]

      if status == "running"
        return container
      else
        if stop
          return false
        end
        res = container.start()
        if res.info["State"]["Status"].eql? "exited" and  res.info["State"]["Error"].include? "port is already allocated"
          return create_container()
        end
        return container
      end
    end
  rescue => e
    if e.message.include? "No such container"

      return create_container()
    else
      return false
    end
  end

end