Execute docker build and push using docker caches with multi stage.
The docker multi stages are inferred from the Dockerfile.
Download the binary releases
Linux
git clone https://github.com/devmasx/cached-docker ~/.cached-docker
sudo cp ~/.cached-docker/releases/linux/cached-docker /usr/local/bin/cached-docker
Mac OS
git clone https://github.com/devmasx/cached-docker ~/.cached-docker
sudo cp ~/.cached-docker/releases/macos/cached-docker /usr/bin/cached-docker
Or build the source code:
crystal build src/cached_docker.cr --release --static --no-debug -o /usr/bin/cached-docker
cached-docker help
Alias | Flag | Description | Default |
---|---|---|---|
-i | --image-name | Image name without tag or image names separated by comma | |
-t | --image-tag | Image tag | Time in unix seconds |
--build-params | Add any docker build flag, --build-params="--build-arg=TOKEN=$TOKEN" | ||
-f | --file | Name of the Dockerfile | ./Dockerfile |
-c | --context | Docker context (path of source code) | . |
--cache-stage-target | Name of the stage target for use in cache. | first stage | |
Only print docker commands | false | ||
-v | --version | Version | |
-h | --help | Help for this command. | false |
Example:
cached-docker -i image-name
Execute this docker commands:
docker pull image-name || exit 0
docker pull image-name:cache-builder || exit 0
docker build --cache-from=image-name:cache-builder --cache-from=image-name --target builder .
docker build --cache-from=image-name:cache-builder --cache-from=image-name -t image-name -t image-name:1580121987 .
docker push image-name:cache-builder
docker push image-name:1580121987
docker push image-name
To increase the speed of your Docker image build is by specifying a cached image that can be used for subsequent builds. You can specify the cached image by adding the --cache-from argument, which will instruct Docker to build using that image as a cache source.
Each Docker image is made up of stacked layers. Using --cache-from rebuilds all the layers from the changed layer until the end of the build; therefore using --cache-from is not beneficial if you change a layer in the earlier stages of your Docker build.
It is recommended that you always use --cache-from for your builds, but keep the following caveats in mind:
You need a previously built Docker image to cache from. The cached image must be retrieved from a registry, which may add to the time it takes to build.
- Fork it (https://github.com/devmasx/cached-docker/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
- Miguel Savignano - creator and maintainer.