Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/docker/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,15 @@ def store_file(path, file_content)
archive_in_stream("/", overwrite: true) { output_io.read }
end

# Keys that /containers/create takes as query parameters rather than in the
# request body. The daemon silently ignores them if they are sent in the
# body, so a misplaced key means the option has no effect at all.
CREATE_QUERY_KEYS = %w[name platform].freeze

# Create a new Container.
def self.create(opts = {}, conn = Docker.connection)
query = opts.select {|key| ['name', :name].include?(key) }
clean_opts = opts.reject {|key| ['name', :name].include?(key) }
query = opts.select { |key| CREATE_QUERY_KEYS.include?(key.to_s) }
clean_opts = opts.reject { |key| CREATE_QUERY_KEYS.include?(key.to_s) }
resp = conn.post('/containers/create', query, :body => MultiJson.dump(clean_opts))
hash = Docker::Util.parse_json(resp) || {}
new(conn, hash)
Expand Down
26 changes: 26 additions & 0 deletions spec/docker/container_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,32 @@
expect(subject.json["Name"]).to eq("/bob")
end
end

context 'when a platform is given' do
let(:opts) { {"platform" => "linux/amd64"} }

# /containers/create takes platform as a query parameter. A "platform"
# body key is accepted and silently ignored by the daemon, so sending it
# in the body means the requested platform has no effect at all.
it 'sends the platform as a query parameter' do
expect(Docker.connection).to receive(:post).with(
'/containers/create',
hash_including('platform' => 'linux/amd64'),
anything
).and_return('{"Id":"deadbeef"}')

subject
end

it 'does not send the platform in the body' do
expect(Docker.connection).to receive(:post) { |_path, _query, opts|
expect(MultiJson.load(opts[:body])).to_not have_key('platform')
'{"Id":"deadbeef"}'
}

subject
end
end
end

describe '#rename' do
Expand Down
Loading