Docker related utilities.
Latest release 20260531:
- DockerUtilCommand.cmd_run: give a more informative name to the temporary directory for mounts.
- DockerRun: build the docker command more nicely, call run(...,fold=True) for more readable tracing.
- DockerRun: add .docker_exe as a field, run as the current user by default, drop .as_root and replace with .user, honour $DK_COMMAND as the default docker command name, adjust option usage on that basis.
Short summary:
docker: Invokedockerwithdk_argv.docker_compose: Invokedocker-composewithdc_argv.DockerRun: ADockerRunspecifies how to prepare docker to execute a command.DockerUtilCommand: A command line mode for working with Docker et al.DockerUtilCommandOptions: Command line options forDockerUtilCommand.main: Invoke theDockerUtilCommandwithargv.mount_escape: Escape the strings inargsfor us in thedocker run --mountoption.
Module contents:
-
default_docker_command(): pylint: disable=unnecessary-lambda-assignment -
default_docker_compose_command(): pylint: disable=unnecessary-lambda-assignment -
default_docker_compose_config(): pylint: disable=unnecessary-lambda-assignment -
docker(*dk_argv, exe=None, doit=True, quiet=True) -> subprocess.CompletedProcess: Invokedockerwithdk_argv. -
docker_compose(*dc_argv, exe=None, config=None, doit=True, quiet=True) -> subprocess.CompletedProcess: Invokedocker-composewithdc_argv. -
class DockerRun: ADockerRunspecifies how to prepare docker to execute a command.This is a generic wrapper for invoking a docker image and internal executable to process data from the host system, essentially a flexible and cleaned up version of the wrappers used to invoke things like the
linuxserver:*utility docker images.Input paths for the executable will be presented in a read only directory, by default `/input' inside the container.
An output directory (default '.', the current durectory) will be mounted read/write inside the container, by default
/outputinside the container.Unlike a lot of docker setups, the default mode runs as the invoking user's UID/GID inside the container and expects the
s6-setuidgidutility to be present in the image.See the
ffmpeg_dockerfunction fromcs.ffmpegutilsfor an example invocation of this class.
DockerRun.add_input(self, infspath: str) -> str:
Add a host filesystem path to the input_map
and return the corresponding container filesystem path.
DockerRun.add_output(self, outfspath: str) -> str:
Add a host filesystem path to the output_map
and return the corresponding container filesystem path.
DockerRun.popopts(self, argv: List[str]) -> None:
Pop options from the list argv.
The command's working directory will be /output. -i inputpath Mount inputpath as /input/basename(inputpath) -U Update the local copy of image before running. Other options are passed to "docker run".
DockerRun.run(self, *argv, doit=None, quiet=None):
Run a command via docker run.
Return the CompletedProcess result or None if doit is false.
-
class DockerUtilCommand(cs.cmdutils.BaseCommand): A command line mode for working with Docker et al.Usage summary:
Usage: dockerutil [common-options...] [options...] [@container] subcommand... -f docker-compose.yml Specify ['docker', 'compose'] YAML file. Default: 'docker-compose.yml', overridden by $DK_COMPOSE_YML @container Specify a target container. Subcommands: help [common-options...] [-l] [-s] [subcommand-names...] Print help for subcommands. This outputs the full help for the named subcommands, or the short help for all subcommands if no names are specified. Options: -l Long listing. -r Recurse into subcommands. -s Short listing. info [common-options...] [field-names...] Recite general information. Explicit field names may be provided to override the default listing. ps [common-options...] Show the running docker containers. repl [common-options...] Run a REPL (Read Evaluate Print Loop), an interactive Python prompt. Options: --banner banner Banner. run [common-options...] [options] image [command] [arg...] Invoke command in an instance of image. A read only directory for input data will be present as /input. A read/write directory for output data will be present at /output. The command's working directory will be /output. -i inputpath Mount inputpath as /input/basename(inputpath) -U Update the local copy of image before running. Other options are passed to "docker run". shell [common-options...] Run a command prompt via cmd.Cmd using this command's subcommands.
DockerUtilCommand.Options
DockerUtilCommand.apply_preargv(self, argv):
Consume a leading @container_name if present.
DockerUtilCommand.cmd_ps(self, argv):
Usage: {cmd}
Show the running docker containers.
DockerUtilCommand.cmd_run(self, argv):
Usage: {cmd} [options] image [command] [arg...]
Invoke command in an instance of image.
A read only directory for input data will be present as /input.
A read/write directory for output data will be present at /output.
The command's working directory will be /output.
-i inputpath
Mount inputpath as /input/basename(inputpath)
-U Update the local copy of image before running.
Other options are passed to "docker run".
DockerUtilCommand.docker(self, *dk_argv) -> subprocess.CompletedProcess:
Invoke docker.
DockerUtilCommand.docker_compose(self, *dc_argv) -> subprocess.CompletedProcess:
Invoke docker-compose.
-
class DockerUtilCommandOptions(cs.cmdutils.BaseCommandOptions): Command line options forDockerUtilCommand. -
main(argv=None, **run_kw): Invoke theDockerUtilCommandwithargv. -
mount_escape(*args) -> str: Escape the strings inargsfor us in thedocker run --mountoption.Apparently the arguments to
docker run --mountare in fact a CSV data line. (Of course you need to find this allusion in the bug tracker, heaven forfend that the docs actually detail this kind of thing.)Rather that try to enumerate what needs escaping, here we use the
csvmodule to escape using the default "excel" dialect.
Release Log
Release 20260531:
- DockerUtilCommand.cmd_run: give a more informative name to the temporary directory for mounts.
- DockerRun: build the docker command more nicely, call run(...,fold=True) for more readable tracing.
- DockerRun: add .docker_exe as a field, run as the current user by default, drop .as_root and replace with .user, honour $DK_COMMAND as the default docker command name, adjust option usage on that basis.
Release 20240519: DockerRun.outputpath: rename to output_hostdir, less confusing.
Release 20240305: DockerRun: new "network" attribute, default "none", for the --network CLI option.
Release 20240201:
- mount_escape: strip trailing carriage return also.
- DockerRun: new output_map attribute much like input_map; also mount existing outputs within the container.
Release 20231202: Initial PyPI release.
Release files for cs-dockerutils 20260531
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cs_dockerutils-20260531.tar.gz | 6.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cs_dockerutils-20260531-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 14.7 kB
Release files / cs_dockerutils-20260531.tar.gz
| Download URL | cs_dockerutils-20260531.tar.gz |
|---|---|
| Size | 6.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4ba9d5b1a936366e31d47d1ab08f9b0a95c98590a31cfd05442d00cf7ad5e608
|
|
BLAKE2b-256 checksum How to use checksums |
38d238d2f73cbe23ce822b95dfe8b139cbe5c1408d0173943aa1592d11adb271
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Release files / cs_dockerutils-20260531-py2.py3-none-any.whl
| Download URL | cs_dockerutils-20260531-py2.py3-none-any.whl |
|---|---|
| Size | 7.9 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
a6f8624d05e630a4f4c04f9d25a962ac4031f623f3621f41d6f5432ecedf60eb
|
|
BLAKE2b-256 checksum How to use checksums |
5cc09bcdeffb25a83ce3502025a0b765a7584af8a42ecccedc7e53a028575294
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|