diff --git a/lib/docker/image.rb b/lib/docker/image.rb index ac97814e7..120a082c6 100644 --- a/lib/docker/image.rb +++ b/lib/docker/image.rb @@ -100,8 +100,9 @@ def create(opts = {}, creds = nil, conn = Docker.connection) headers = !credentials.nil? && Docker::Util.build_auth_header(credentials) headers ||= {} body = conn.post('/images/create', opts, :headers => headers) - id = Docker::Util.fix_json(body).select { |m| m['id'] }.last['id'] - new(conn, 'id' => id, :headers => headers) + json = Docker::Util.fix_json(body) + image = json.reverse_each.find { |el| el && el.key?('id') } + new(conn, 'id' => image && image.fetch('id'), :headers => headers) end # Return a specific image.