Class: MockServerWorldHelpers::LocalDockerServer
- Inherits:
-
Object
- Object
- MockServerWorldHelpers::LocalDockerServer
- Defined in:
- lib/local-docker-server.rb
Instance Attribute Summary collapse
-
#is_started ⇒ Object
Returns the value of attribute is_started.
Instance Method Summary collapse
- #create ⇒ Object
- #delete ⇒ Object
-
#initialize(public_port = 8080) ⇒ LocalDockerServer
constructor
A new instance of LocalDockerServer.
Constructor Details
#initialize(public_port = 8080) ⇒ LocalDockerServer
Returns a new instance of LocalDockerServer.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/local-docker-server.rb', line 7 def initialize(public_port = 8080) @name = "mockserver-world" @image_name = "jamesdbloom/mockserver" @private_port = 1080 @public_port = public_port @is_started = false if Docker::Image.get(@image_name) == nil system "docker pull #{@image_name}" end end |
Instance Attribute Details
#is_started ⇒ Object
Returns the value of attribute is_started.
5 6 7 |
# File 'lib/local-docker-server.rb', line 5 def is_started @is_started end |
Instance Method Details
#create ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/local-docker-server.rb', line 20 def create delete ports = [{"PrivatePort"=>@private_port, "PublicPort"=>@public_port, "Type"=>"tcp"}] @container = Docker::Container.create('Image' => "#{@image_name}", "Ports"=> ports, "name" => "#{@name}") port_bindings = {"#{@private_port}/tcp"=>[{"HostIp"=>"0.0.0.0", "HostPort"=>"#{@public_port}"}]} result_container = @container.start("PortBindings"=> port_bindings) @is_started = result_container.json["State"]["Running"] raise "Unable to start Docker container. Docker must be installed" unless @is_started end |
#delete ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/local-docker-server.rb', line 33 def delete if @container != nil @container.stop @container.delete(:force => true) end delete_all_named_containers @is_started = false end |