Docker helper scripts

January 27, 2023 ยท View on GitHub

License Awesomebot mega-linter GitHub stars

Table of Contents

This is a collection of docker helper scripts, packaged as a ZSH plugin to make it easier to use with frameworks like zgenom and antigen.

Most of these were collected from blog posts, gists, slack - basically stuff I saw and thought was useful enough to stash away, and I've given credit where I know the source.

If you wrote something I've collected and I didn't credit you, please create an issue or PR so I can correct it.

Script list

CommandDescriptionCredit
boot2docker-timesyncboot2docker drifts out of time sync every time my MacBook Pro sleeps. Run this to resync.
diveWrapper script that calls wagoodman/dive to analyze a container image.
docker-check-for-image-updateCheck if a given image has been updated, and if so, run a command.Matthias Lohr's blog
docker-container-volumesList the volumes attached to a container.http://www.tech-d.net/2014/05/05/docker-quicktip-5-backing-up-volumes/)
docker-create-backup-containerCreates a container with all the volumes from all the containers on the host.From http://www.tech-d.net/2014/05/05/docker-quicktip-5-backing-up-volumes/
docker-delete-stopped-containersCleans up stale stopped containers.
docker-hereBuilds an ephemeral container, runs it with the parameters you pass docker-here, then deletes the ephemeral container.
docker-ipGets the pid of a running container.
docker-lastPrint the id of the last container you ran.
docker-lintLint a Dockerfile with hadolint.
docker-pidPrint pid of a running container.
docker-ps-cleanupCleans up docker ps output by deleting all exited containers.
docker-purge-unnamed-imagesCleans up image cruft by deleting all the images that aren't named.
docker-remove-dangling-imagesCleans up image cruft by deleting all dangling images.
docker-runcUses fzf to select an image and run a command in it.
docker-runincUses fzf to select a running container and run a command inside it.
docker-shellRuns a shell inside a container with pwd mounted as /pwd. Defaults to bash inside debian:buster-slim, reads shell & image name from STANDARD_DOCKER_COMMAND and STANDARD_DOCKER_IMAGE or $1 and $2.
docker-showipcShow the IP of a running docker container.
docker-stopcStops and/or removes a docker container.
docker-supercleanClear out any stopped containers or stale images.
docker-update-all-imagesUpdate all images on the machine.
fzf-docker-attachUse fzf to select a docker container to start and attach to
fzf-docker-rmUse fzf to select a docker container to remove
fzf-docker-stopUse fzf to select a docker container to stop

Installing

Pre-Requisites

No matter how you choose to install the plugin, it has the following pre-requisites:

  • jq - Install with brew install jq
  • fzf - Install with brew install fzf

zgenom

Add zgenom load unixorn/docker-helpers.zshplugin to your .zshrc wherever you're loading your other plugins.

Antigen

Add antigen bundle unixorn/docker-helpers.zshplugin to your .zshrc with your other plugins. You can test drive them without editing your .zshrc by running antigen bundle unixorn/docker-helpers.zshplugin in a running zsh session.

Oh-My-Zsh

  1. cd to your oh-my-zsh plugins directory (~/.oh-my-zsh/custom/plugins)
  2. git clone https://github.com/unixorn/docker-helpers.zshplugin docker-helpers
  3. Add docker-helpers to your plugins in your .zshrc
...
plugins=( ... docker-helpers ...)
...

Other useful Docker stuff

  • If you use Sublime Text 2/3, check out sublime-docker. Lets you build inside Docker containers directly from Sublime Text.
  • dive - A tool for exploring a docker image, layer contents, and discovering ways to shrink your Docker image size.