docker compose cache code example
Example 1: docker-compose force rebuild
docker-compose up --build
docker-compose up --force-recreate
Example 2: docker-compose compose clear cache
sudo docker-compose rm -f
Example 3: docker compose use cache from image
image: docker:stable
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay2
CACHE_IMAGE: mjhea0/docker-ci-cache
DOCKER_BUILDKIT: 1
stages:
- build
docker-build:
stage: build
before_script:
- docker login -u $REGISTRY_USER -p $REGISTRY_PASS
script:
- docker build
--target base
--cache-from $CACHE_IMAGE:base
--tag $CACHE_IMAGE:base
--file ./Dockerfile.multi
--build-arg BUILDKIT_INLINE_CACHE=1
"."
- docker build
--cache-from $CACHE_IMAGE:base
--cache-from $CACHE_IMAGE:stage
--tag $CACHE_IMAGE:stage
--file ./Dockerfile.multi
--build-arg BUILDKIT_INLINE_CACHE=1
"."
after_script:
- docker push $CACHE_IMAGE:stage