求教如何在如下数据中取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获得,相应源代码如下。
ruby
def self.all(opts = {}, conn = Docker.connection) hashes = Docker::Util.parse_json(conn.get('/containers/json', opts)) || [] hashes.map { |hash| new(conn, hash) } end
Je ne comprends pas très bien ce que vous voulez dire, mais la valeur de hachage est très simple :
par exemple