Fix broken and outdated README examples - #606
Open
tas50 wants to merge 1 commit into
Open
Conversation
Audited every example in the README against a live daemon. All ten Ruby
blocks now parse under `ruby -c`; three did not before.
Syntax errors:
- `container.update("CpuShares" => 50000")` had an unbalanced quote.
- `Docker::Event.stream({ read_timeout: 60 * 60 * 24) })` had a stray
paren.
- Pasted command output (a tar dump, event to_s lines, streaming log
lines) sat inside ruby blocks as bare tokens. Commented out.
Wrong documented return values, all checked against a running daemon:
- `image.save('my_export.tar')` returns nil, not a Docker::Image.
Image#save only returns a String when no filename is given.
- `container.run('pwd', 10)` returns a Docker::Container, not a
Docker::Image. It commits the container and runs the command in the
resulting image, and Image#run returns a Container.
- `image.remove(:force => true)` returns the raw response body, not true.
Event read timeouts. The first argument to Event.stream and Event.since
is the query parameter hash for /events, not Excon options, so
`Event.stream({ read_timeout: 0 })` sent read_timeout=0 to Docker as a
query parameter and left the timeout untouched. Documented setting it on
the connection instead. Also noted that the global
`Docker.options[:read_timeout] = ...` form only takes effect if set
before the default connection is first used, since Docker.connection is
memoized and Connection#initialize copies the options hash.
`container.exec(['date'], stderr: false)` was documented as returning
only stdout. It does not: Container#exec computes stderr as
`options.delete(:stderr) || !detach`, so passing false still resolves to
true and stderr is captured. Replaced with destructuring the documented
[stdout, stderr, exit_code] return value. The underlying behaviour looks
like a bug, but that is a code change rather than a docs one, so it is
left alone here.
Stale references:
- The `base` image no longer exists on Docker Hub ("pull access denied
for base, repository does not exist"). Four examples used it; switched
to debian:stable, which is what the specs use.
- `sudo docker -d` fails with "unknown shorthand flag: 'd'". Now dockerd.
- The docker_remote_api_v1.14 doc links 404.
- `docker images <IMAGE.ID>` is not the equivalent of Image.get, which
hits /images/{id}/json. That is docker inspect.
- ubuntu:14.04 went EOL in 2019; use 24.04.
- Dropped the "meant to interface with Docker version 1.4.*" claim. The
gem sends no API version prefix, so requests use the daemon default.
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.
Audited every example in the README against a live Docker daemon. All ten Ruby blocks now parse under
ruby -c; three did not before.Syntax errors
container.update("CpuShares" => 50000")Docker::Event.stream({ read_timeout: 60 * 60 * 24) })to_slines, streaming log lines) — now commentedWrong documented return values
Each checked against a running daemon:
image.save('my_export.tar')returnsnil, not aDocker::Image.Image#saveonly returns aStringwhen no filename is given.container.run('pwd', 10)returns aDocker::Container, not aDocker::Image. It commits the container and runs the command in the resulting image, andImage#runreturns aContainer.image.remove(:force => true)returns the raw response body, nottrue.Event read timeouts
The first argument to
Event.streamandEvent.sinceis the query parameter hash for/events, not Excon options. So the documentedsent
read_timeout=0to Docker as a query parameter and left the timeout entirely untouched. I confirmed this by tracing the call:The section now documents setting it on the connection, which does work. It also notes that the global
Docker.options[:read_timeout] = ...form only takes effect if set before the default connection is first used —Docker.connectionis memoized, andConnection#initializecopies the options hash for unix sockets, so mutating it afterwards is silently ignored.A code bug this turned up
container.exec(['date'], stderr: false)was documented as returning only stdout. It does not.Container#execcomputesso passing
stderr: falseyieldsfalse || true→true, and stderr is still captured. Verified:I replaced the example with destructuring the documented
[stdout, stderr, exit_code]return value rather than papering over it. Fixing the actual behaviour is a code change rather than a docs one, so I have left it alone here — happy to follow up separately if you would likestderr: falseto work as advertised.Stale references
baseimage no longer exists on Docker Hub (pull access denied for base, repository does not exist). Four examples used it; switched todebian:stable, which is what the specs use.sudo docker -dfails withunknown shorthand flag: 'd'. Nowdockerd.docker_remote_api_v1.14doc links 404.docker images <IMAGE.ID>is not the equivalent ofImage.get, which hits/images/{id}/json. That isdocker inspect.Verification
Every corrected example was run against Docker 29.7.2 (API 1.55):
Docs only — no library code is touched.