0
0
Dockerdevops~10 mins

Docker layer caching in CI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to specify the base image in a Dockerfile.

Docker
FROM [1]
Drag options to blanks, or click blank then click option'
ARUN apt-get update
Bubuntu:20.04
CCOPY . /app
DCMD ["bash"]
Attempts:
3 left
💡 Hint
Common Mistakes
Using RUN or COPY instead of a base image after FROM.
Leaving FROM instruction empty.
2fill in blank
medium

Complete the GitHub Actions step to restore Docker cache using actions/cache.

Docker
- name: Restore Docker cache
  uses: actions/cache@v3
  with:
    path: /tmp/.buildx-cache
    key: ${{ runner.os }}-docker-[1]
Drag options to blanks, or click blank then click option'
Abuildx-cache
Bdockerfile
Ccache-key
Dimage-tag
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated strings like 'dockerfile' or 'image-tag' as cache keys.
Not including runner.os in the key for OS-specific caching.
3fill in blank
hard

Fix the error in the Docker build command to enable cache from a local directory.

Docker
docker buildx build --cache-from=type=local,src=[1] --cache-to=type=local,dest=/tmp/.buildx-cache .
Drag options to blanks, or click blank then click option'
A/tmp/.buildx-cache
B/var/lib/docker
C/cache/buildx
D/home/user/cache
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated directories that do not contain the cache.
Mismatching cache-from and cache-to paths.
4fill in blank
hard

Fill both blanks to create a Docker build command that pushes the image and uses cache correctly.

Docker
docker buildx build --push --tag myimage:latest --cache-from=type=[1],src=/tmp/.buildx-cache --cache-to=type=[2],dest=/tmp/.buildx-cache .
Drag options to blanks, or click blank then click option'
Alocal
Bregistry
Cinline
Dgha
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing different cache types for from and to options.
Using 'registry' or 'inline' when local caching is intended.
5fill in blank
hard

Fill all three blanks to define a GitHub Actions job step that builds, caches, and pushes a Docker image.

Docker
- name: Build and push Docker image
  run: |
    docker buildx build \
    --tag myapp:latest \
    --cache-from=type=[1],src=/tmp/.buildx-cache \
    --cache-to=type=[2],dest=/tmp/.buildx-cache \
    --push .
  env:
    DOCKER_BUILDKIT: [3]
Drag options to blanks, or click blank then click option'
Alocal
C1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using different cache types for from and to.
Forgetting to enable BuildKit by setting DOCKER_BUILDKIT=1.