Skip to content

Correct README examples that do not match the library's behavior - #619

Merged
ls-todd-lunter merged 1 commit into
upserve:masterfrom
tas50:fix-readme-example-correctness
Oct 27, 2026
Merged

ls-todd-lunter merged 1 commit into
upserve:masterfrom
tas50:fix-readme-example-correctness

Conversation

@tas50

@tas50 tas50 commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

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

  • Rake task: Docker::Image.run('rm -rf /etc') raises NoMethodError because run is an instance method. The example now calls image.run(...). It also waits for the command to finish before commit; without the wait, the commit captured the container before the command's changes landed.
  • Rake task, second image: 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 now Docker::Image.get('repo:tag').
  • build_from_dir streaming: a single chunk can contain several newline-separated JSON messages, so JSON.parse(chunk) raised JSON::ParserError. The example now parses each line.

Return values and descriptions

  • Image#tag returns every repo tag the image has, and the tag defaults to latest. Dropped force, which the tag endpoint no longer accepts.
  • Container#export returns the container, not nil. The example now opens the tar in binary mode.
  • Fixed the bracketing of the Container#attach return value ([[stdout...], [stderr...]]).
  • A PortBindings entry of [{}] publishes the port to a random host port, which is docker run -p 1234, not a bridge-only expose.
  • Explained what Container#run's second argument actually does: it's how long to wait for the current command to finish.
  • Moved Container#update before Container#delete; updating a deleted container raises NotFoundError.
  • Event#to_s sample output now uses the actor-style format current Docker produces.
  • Corrected the note about the options hash: for Event.since it's the second argument, after the timestamp.
  • Docker::Image.new is not private, so the Images intro no longer says it is. It also lists .get and .all as ways to get an instance.

Not addressed here

When testing the Rake DSL, I found that image 'repo:tag' doesn't register a task named repo:tag on current Rake. Rake treats repo: as a namespace, and Docker::ImageTask.scope_name drops it, so the task becomes tag. That's a library bug rather than a docs bug, so I'll handle it separately.

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>
@ls-todd-lunter
ls-todd-lunter merged commit 56734b6 into upserve:master Oct 27, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants