This repository hosts utilities used by other repositories that build or manage Docker images.
-
Add this repository as a git submodule.
git submodule add https://github.com/beeglercorp/docker-util.git
-
You probably don't care about the history, so configure the submodule to clone shallowly.
git config -f .gitmodules submodule.docker-util.shallow true
You may wish to use a particular version. To update the submodule to use a specific release (i.e. tag), run the following, making sure to replace {VERSION} with the version you desire.
cd docker-util
git fetch --tags
git checkout v{VERSION}
cd ../
If you prefer to use a branch, rather than a version (see above), periodically you will want to pull in the latest commits from the remote repository.
git submodule update --recursive --remote docker-util
Then, commit and push as usual.
Use the attempt.sh
script to register the attempt
command. You may use this to retry fickle commands, such as docker version
, that may fail during certain race conditions.
source docker-util/sh/attempt.sh && attempt <expression>
The following will execute the docker login
command up to 5 times, pausing 1 second in between attempts. If the docker login expression exits with a 0 status code during any of the attempts, the script will simply echo the expression's output. Otherwise it will log stdout and stderr, and exit with a 1 status code after the 5th attempt.
source docker-util/sh/attempt.sh && attempt docker login
Use the compare-images.sh
script to compare 2 images by name. See the docker save
documentation for valid IMAGE parameter values.
docker-util/sh/compare-images.sh <IMAGE> <IMAGE>
The following will exit with a 0 status code if both foo and bar images exist, and the foo image produces an identical archive as the bar image.
docker-util/sh/compare-images.sh foo bar
The following all exit with a 1 status code.
# given _foo_ and _bar_ exist, but differ
docker-util/sh/compare-images.sh foo bar
# given the _foo_ image does not exist
docker-util/sh/compare-images.sh foo bar
# given the _bar_ image does not exist
docker-util/sh/compare-images.sh foo bar
# too few arguments
docker-util/sh/compare-images.sh foo
# too many arguments
docker-util/sh/compare-images.sh foo bar baz
Use the install-docker-on-trusty.sh
script to update the Docker installation. You will typically run this in a Travis container, via .travis.yml.
.travis.yml
before_install:
- ./docker-util/sh/install-docker-on-trusty.sh
- sudo dockerd --experimental &
Use the push-image.sh
script to docker login
and then docker push
an existing, top-level image.
docker-util/sh/push-image.sh -i <image> -n <name> -p <password> -t [<tag>] -u <username>
Use the test-image-size.sh
script to test the size of an image, in MB, against a threshold.
docker-util/sh/test-image-size.sh -i <image> -t <threshold>
The following will exit with a 0 status code if the foo image is less than or equal to 25MB. If the image is greater than 25MB, the script will exit with a 1 status code.
docker-util/sh/test-image-size.sh -i foo -t 25
Use the validate-alpine-version.sh
script to ensure that your container runs on an expected Alpine version.
docker-util/sh/validate-alpine-version.sh -i <image> -v 3.6
The following will exit with a 0 status code.
docker-util/sh/validate-alpine-version.sh -i beeglercorp/travis-cli:alpine-3.5 -v 3.5
The following will exit with a 1 status code.
docker-util/sh/validate-alpine-version.sh -i beeglercorp/travis-cli:alpine-3.5 -v 3.6