Feature request, dry run mode that prints the cli commands
I have a feature request (That im willing to contribute towards if you'll be interested).
When developing with docker in my workplace, we often use the docker cli or the docker compose config yaml.
The only cases where we use the python SDK is when we need the run to be dynamically generated to the point where scripting the CLI command wont be too ugly/dirty.
Whenever me and my team try to use the SDK, we always have bugs in our development cycle that stem from the fact that we accidentally did not translate the CLI syntax to the SDK syntax correctly.
It would be very useful if the SDK's client.containers.run end point (and maybe some others) took something like a dryrun flag,
such that when its true, we would only get the cli command that would have been equivalent to the SDK run. If such a feature would be implemented, we could simply run the SDK in dryrun mode until we got the exact command we wanted and only then switched it off, making the development experience much better.
Is this possible/desirable?
Thanks in advance for reading.
Hey, do you have idea for the implementation?
From browsing the source code for this project, specifically https://github.com/docker/docker-py/blob/main/docker/api/build.py I can see that the params are basically collected into the format of the API (mostly to the params key).
I suggest that before the API request is sent, we check if the dryrun flag is on and in that case we format the API request to the shape of the CLI command.
This will require something like a jinja2 format string that can turn the API call into the CLI format.
Another, solution which is slightly less helpful but is much easier to implement, is to print/return the API request as a json if the dryrun flag is on. In that case, we simply print the payload and exit before sending the command.
Most users will know the CLI and not the API but it might be a nice compromise.
Yeah, that seems a fine way.
@milas Could you please tag it as feature-request
@DeanLight It would require changes to create_container and build method of low-level api implementation at least so, quite some work
@Khushiyant Yeah that makes sense.
Hey @DeanLight, while I can understand the interest for this, I don't think this is trivially possible, since the docker-py API is interacting with the Engine API directly and the commands might simply not map 1:1 to Docker CLI commands.
If anything, logging out the Engine API calls would be more realistic to achieve.
@kiview I agree. So if we are tagging it as a feature request, lets go with returning the API json given the dry-run flag.