求教如何在如下数据中取 PublicPort 或 Image
[#<Docker::Container:0x00000005195578 @id="8aba2f87cdf5e5d340f30fef8e5df8f58d990eab1c70583d4fef3a8fa83de3f2", @info={"Command"=>"/bin/bash", "Created"=>1427722904, "Image"=>"ddddd:latest", "Names"=>["/clever_pike"], "Ports"=>[{"IP"=>"0.0.0.0", "PrivatePort"=>80, "PublicPort"=>10280, "Type"=>"tcp"}], "Status"=>"Up 10 days", "id"=>"8aba2f87cdf5e5d340f30fef8e5df8f58d990eab1c70583d4fef3a8fa83de3f2"}, @connection=#<Docker::Connection:0x00000004aaadf8 @url="unix:///", @options={:socket=>"/var/run/docker.sock"}>>, #<Docker::Container:0x00000005195488 @id="c95642d254f1b716debbc8f5381b1234aff69c92db87a43e9b6f64216d1471b3", @info={"Command"=>"/bin/bash", "Created"=>1427722902, "Image"=>"bbbbbbb:latest", "Names"=>["/serene_heisenberg"], "Ports"=>[{"IP"=>"0.0.0.0", "PrivatePort"=>80, "PublicPort"=>10180, "Type"=>"tcp"}], "Status"=>"Up 10 days", "id"=>"c95642d254f1b716debbc8f5381b1234aff69c92db87a43e9b6f64216d1471b3"}, @connection=#<Docker::Connection:0x00000004aaadf8 @url="unix:///", @options={:socket=>"/var/run/docker.sock"}>>]
以上直接调用 docker-api,d=Docker::Container.all 获得,相应源代码如下。
def self.all(opts = {}, conn = Docker.connection)
hashes = Docker::Util.parse_json(conn.get('/containers/json', opts)) || []
hashes.map { |hash| new(conn, hash) }
end
通过 pp 结果输出如下
[#<Docker::Container:0x007fe34c722018
@connection=
#<Docker::Connection:0x007fe34d353af8
@options={:socket=>"/var/run/docker.sock"},
@url="unix:///">,
@id="c95642d254f1b716debbc8f5381b1234aff69c92db87a43e9b6f64216d1471b3",
@info=
{"Command"=>"/bin/bash",
"Created"=>1427722902,
"Image"=>"dddd:latest",
"Names"=>["/serene_heisenberg"],
"Ports"=>
[{"IP"=>"0.0.0.0",
"PrivatePort"=>80,
"PublicPort"=>10180,
"Type"=>"tcp"}],
"Status"=>"Up 12 days",
"id"=>"c95642d254f1b716debbc8f5381b1234aff69c92db87a43e9b6f64216d1471b3"}>,
#<Docker::Container:0x007fe34c721f28
@connection=
#<Docker::Connection:0x007fe34d353af8
@options={:socket=>"/var/run/docker.sock"},
@url="unix:///">,
@id="5583df725fa5917eee6609210fee422d6d1d0059f8a9c630bdbf407d6cd014fc",
@info=
{"Command"=>"/bin/bash",
"Created"=>1427722900,
"Image"=>"vvvvv:latest",
"Names"=>["/adoring_franklin"],
"Ports"=>
[{"IP"=>"0.0.0.0",
"PrivatePort"=>80,
"PublicPort"=>10080,
"Type"=>"tcp"}],
"Status"=>"Up 12 days",
"id"=>"5583df725fa5917eee6609210fee422d6d1d0059f8a9c630bdbf407d6cd014fc"}>]