Skip to content

This wraps the Docker CLI so that it establishes saner defaults for my own needs.

Notifications You must be signed in to change notification settings

trajano/docker-cli

Repository files navigation

Wrapped Docker CLI

This wraps the Docker CLI so that it establishes saner defaults for my own needs.

What this does

  • docker run will set to logging to none and -it by default

  • docker rm is forced

    • and remove anonmized volumes
  • docker nuke will remove all running containers and associated volumes (no warning, primarilly used for development when I just want a clean slate without doing a full reset)

  • docker ls maps to docker ps

  • docker ps will actually call docker inspect then render the data using github.com/jedib0t/go-pretty.

    • Primarily because I want to know WHEN the bloody container started,
    • how long it took to start rather than about a minute ago.
    • Show ports only if I am not running in service mode
  • docker service restart maps to docker service update --force

  • docker service ls shows only relavent columns

    • drop :latest if that's the image tag
    • use github.com/jedib0t/go-pretty to render the table
    • --down to list services that are not fully up
  • docker service env shows the environment variables

  • docker service ps without the service list will do all services

    • if primary is running and is desired to be running, don't bother showing the others
  • docker ptag to tag and push image in one command

    • -p to add support for generating a patch tag
  • docker ports lists exposed local port mappings with some specific tweaks for HTTPm that way I can simply ctrl-click the text on the terminal.

    • if container has an image containing httpd or ngnix display as http://localhost:{port}
    • if container internal port is 80, 3000 or 8080 display as http://localhost:{port}
  • docker build adds implicit secrets to the build.

    • docker build maps to docker buildx build --load which will use the builder specified by docker buildx use.
    • init-gradle == $HOME/.gradle/init.gradle
    • npmrc == $HOME/.npmrc
    • settings-xml == $HOME/.mvn/settings.xml
    • aws-credentials == $HOME/.aws/credentials
  • docker bash runs /bin/bash given a container ID

  • docker sh runs /bin/sh given a container ID

  • docker logs like docker logs but starts tailing

    • supports a positional paramter which represents since without having to type in --since
    • the command usage is docker tail [since] [containerID]
  • docker env [containerID] dumps the environment variables for the container sorted

  • docker mnt . mounts the current directory to /mnt and runs alpine image (note any relative path can work)

    • docker mnt . [image] mounts the current directory to /mnt and runs the image specified
    • docker mnt . [image] [cmd...] mounts the current directory to /mnt and runs the image specified with the command
    • docker mnt [volume] [image] mounts the named volume to /mnt and runs the image specified
    • docker mnt [volume] [image] [cmd...] mounts the named volume to /mnt and runs the image specified with the command
  • docker service push <service> <image> replaces the image of the service if image is not provided it pulls and then does the update to ensure it is the latest copy. It will also add --with-registry-auth as appropriate

  • docker use <context> maps to docker context use

  • docker context use allows docker context use <target> which uses the target rather than the context name.

    • automatically create the context if it does not exist
  • docker service --help should call docker service --help but append the extra commands

  • docker service inspect shows data

    • gets rid of the previous spec
    • use network names rather than the IDs
  • docker service logs like docker service logs but starts tailing, passes --raw

    • supports a positional paramter which represents since without having to type in --since
  • docker du shows disk usage stats in JSON

  • docker stat runs docker stats --no-stream with sane columns (i.e. no ID)

  • docker stats runs with sane columns (i.e. no ID) and hopefully less flashing

  • docker context create <name> <dockerhost> maps to docker context create <name> --docker "host=<dockerhost>"

  • docker context create <dockerhost> maps to docker context create <host portion of dockerhost> --docker "host=<dockerhost>"

  • Special handling for ridiculously long image names, specifically "ghcr.io/open-telemetry/opentelemetry-collector-releases/opentelemetry-collector-contrib"

Architecture

  • Use Cobra to manage the CLI
  • Use the CLI for the most part until they have a package that would handle DOCKER_HOST
  • output will be in JSON like the CLI because there's no yaml mappings in the Docker types

About

This wraps the Docker CLI so that it establishes saner defaults for my own needs.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published