Complete the code to specify the base image in a Dockerfile.
FROM [1]The FROM instruction sets the base image for the Docker build. Here, ubuntu:20.04 is a valid base image.
Complete the GitHub Actions step to restore Docker cache using actions/cache.
- name: Restore Docker cache uses: actions/cache@v3 with: path: /tmp/.buildx-cache key: ${{ runner.os }}-docker-[1]
The cache key should be unique to the build context. buildx-cache is commonly used to identify the Docker build cache.
Fix the error in the Docker build command to enable cache from a local directory.
docker buildx build --cache-from=type=local,src=[1] --cache-to=type=local,dest=/tmp/.buildx-cache .
The --cache-from option should point to the directory where the cache was saved, here /tmp/.buildx-cache.
Fill both blanks to create a Docker build command that pushes the image and uses cache correctly.
docker buildx build --push --tag myimage:latest --cache-from=type=[1],src=/tmp/.buildx-cache --cache-to=type=[2],dest=/tmp/.buildx-cache .
Using local for both --cache-from and --cache-to means the cache is stored and retrieved from a local directory.
Fill all three blanks to define a GitHub Actions job step that builds, caches, and pushes a Docker image.
- 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]
The cache types for from and to are both local. Setting DOCKER_BUILDKIT to 1 enables BuildKit, which supports advanced caching.