Skip to main content

Docker related utilities.

Project description

Docker related utilities.

Latest release 20240305: DockerRun: new "network" attribute, default "none", for the --network CLI option.

Function default_docker_command()

pylint: disable=unnecessary-lambda-assignment

Function default_docker_compose_command()

pylint: disable=unnecessary-lambda-assignment

Function default_docker_compose_config()

pylint: disable=unnecessary-lambda-assignment

Function docker(*dk_argv, exe=None, doit=True, quiet=True) -> subprocess.CompletedProcess

Invoke docker with dk_argv.

Function docker_compose(*dc_argv, exe=None, config=None, doit=True, quiet=True) -> subprocess.CompletedProcess

Invoke docker-compose with dc_argv.

Class DockerRun

A DockerRun specifies 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 /output inside 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-setuidgid utility to be present in the image.

See the ffmpeg_docker function from cs.ffmpegutils for an example invocation of this class.

Class DockerUtilCommand(cs.cmdutils.BaseCommand)

A command line mode for working with Docker et al.

Command line usage:

Usage: dockerutil [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 [-l] [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.
      -l  Long help even if no subcommand-names provided.
    ps
      Show the running docker containers.
    run [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)
      --root
          Do not switch to the current effective uid:gid inside
          the container.
      -U  Update the local copy of image before running.
      Other options are passed to "docker run".
    shell
      Run a command prompt via cmd.Cmd using this command's subcommands.

Class DockerUtilCommandOptions(cs.cmdutils.BaseCommandOptions, cs.threads.HasThreadState, cs.context.ContextManagerMixin)

Command line options for DockerUtilCommand.

Function main(argv=None, **run_kw)

Invoke the DockerUtilCommand with argv.

Function mount_escape(*args) -> str

Escape the strings in args for us in the docker run --mount option.

Apparently the arguments to docker run --mount are 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 csv module to escape using the default "excel" dialect.

Release Log

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cs.dockerutils-20240305.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

cs.dockerutils-20240305-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file cs.dockerutils-20240305.tar.gz.

File metadata

  • Download URL: cs.dockerutils-20240305.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for cs.dockerutils-20240305.tar.gz
Algorithm Hash digest
SHA256 96b1fb002c8467ee34d1218f215608b7c373dec26780d36d3a8d20827cf85cf8
MD5 f1de07dd6d61a1b9ccec4b1b42f1a66f
BLAKE2b-256 ee51d34d4fc697851bfa2ae3b1ec68de8e28e5c0c4b0a426e68a189890e94a76

See more details on using hashes here.

File details

Details for the file cs.dockerutils-20240305-py3-none-any.whl.

File metadata

File hashes

Hashes for cs.dockerutils-20240305-py3-none-any.whl
Algorithm Hash digest
SHA256 4785b3538c8f4e98999e41087e63bf2a0ee13bf1a888f55f90c0073e130e9a26
MD5 3f1163207a7098c89ae58df8e89da846
BLAKE2b-256 311518e4ddd49e9bb49e96e9d9151550b1dc9569d9c360dcba56e3c0a4bc9332

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page