Repository navigation
Correct README examples that do not match the library's behavior - #619
Merged
ls-todd-lunter merged 1 commit intoOct 27, 2026
Merged
Conversation
Each example was run against Docker 29.9 (API 1.56) to confirm the fix. - Rake task: Docker::Image.run is not a class method; call run on the image, and wait for the command before committing so the commit includes its result. Look up the locally built image with Docker::Image.get, since Image.create would try to pull it. - Image#tag returns every repo tag on the image, and the force option is no longer accepted by the tag endpoint. - build_from_dir streaming: a chunk can hold several JSON messages, so parse it line by line. - Container#export returns the container; open the tar in binary mode. - Fix the bracketing of the Container#attach return value. - Clarify that PortBindings with an empty binding publishes to a random host port, and what the timeout argument to Container#run does. - Show Container#update before the container is deleted. - Event#to_s output uses the actor style, and Event.since takes the timestamp first and the options hash second. - Docker::Image.new is not private. Signed-off-by: Tim Smith <tsmith84@proton.me>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Several README examples either raise errors or show return values the library doesn't produce. I ran each corrected example against a real daemon (Docker 29.9.2, API 1.56) to confirm the fix.
Examples that failed
Docker::Image.run('rm -rf /etc')raisesNoMethodErrorbecauserunis an instance method. The example now callsimage.run(...). It also waits for the command to finish beforecommit; without the wait, the commit captured the container before the command's changes landed.Docker::Image.create('fromImage' => 'repo', 'tag' => 'tag')tries to pull from a registry, so it can't find the image the previous task just built locally. It is nowDocker::Image.get('repo:tag').build_from_dirstreaming: a single chunk can contain several newline-separated JSON messages, soJSON.parse(chunk)raisedJSON::ParserError. The example now parses each line.Return values and descriptions
Image#tagreturns every repo tag the image has, and the tag defaults tolatest. Droppedforce, which the tag endpoint no longer accepts.Container#exportreturns the container, notnil. The example now opens the tar in binary mode.Container#attachreturn value ([[stdout...], [stderr...]]).PortBindingsentry of[{}]publishes the port to a random host port, which isdocker run -p 1234, not a bridge-only expose.Container#run's second argument actually does: it's how long to wait for the current command to finish.Container#updatebeforeContainer#delete; updating a deleted container raisesNotFoundError.Event#to_ssample output now uses the actor-style format current Docker produces.Event.sinceit's the second argument, after the timestamp.Docker::Image.newis not private, so the Images intro no longer says it is. It also lists.getand.allas ways to get an instance.Not addressed here
When testing the Rake DSL, I found that
image 'repo:tag'doesn't register a task namedrepo:tagon current Rake. Rake treatsrepo:as a namespace, andDocker::ImageTask.scope_namedrops it, so the task becomestag. That's a library bug rather than a docs bug, so I'll handle it separately.