How to Configure Docker Layer Caching Cleanup in AWS
Introduction
Docker Layer Caching (DLC) in Amazon Web Services (AWS) environments uses Elastic Block Store (EBS) volumes to store image layers for reuse across jobs, helping optimize build times. By default, these EBS volumes persist for 3 days after inactivity before being automatically cleaned up. This article explains how to customize the cleanup frequency for DLC volumes to better manage storage costs and resource usage in your CircleCI Server installation.
Prerequisites
Before configuring DLC cleanup settings, ensure you have:
CircleCI Server installed with AWS as your cloud provider
Administrative access to your CircleCI Server configuration
Projects currently using
docker_layer_caching: truein their configurationAccess to modify your
values.yamlfile
Instructions
Step 1: Verify Docker Layer Caching Usage
First, confirm that your projects are actively using Docker Layer Caching:
Check your project's
.circleci/config.ymlfileLook for jobs that include
docker_layer_caching: truein their configurationVerify that these jobs are using either
machineexecutor orsetup_remote_docker
Example configuration:
jobs:
build:
machine:
image: ubuntu-2004:202010-01
docker_layer_caching: trueStep 2: Access Your Values Configuration
Locate your CircleCI Server
values.yamlconfiguration fileOpen the file in your preferred text editor
Find the
vm_serviceblock, or create one if it doesn't exist
Step 3: Configure DLC Cleanup Settings
Add or modify the dlc_lifespan_days setting under the vm_service block:
vm_service:
dlc_lifespan_days: 1 # Set to desired number of days
providers:
# Your existing provider configurationNote: Replace the number 1 with your preferred cleanup interval in days.
Step 4: Apply the Configuration Changes
Save your
values.yamlfileApply the updated configuration to your CircleCI Server installation
Restart the relevant services as needed for your deployment method
Outcome
After completing these steps, your Docker Layer Caching volumes will be automatically cleaned up based on your specified timeframe. EBS volumes will be removed after the configured number of days of inactivity, helping you manage storage costs while maintaining caching benefits.
Additional Notes
Important Considerations:
Jobs that utilize DLC may experience fewer cache hits if you set cleanup to occur more frequently than cache creation
Shorter cleanup intervals reduce storage costs but may impact build performance
Consider your team's build frequency when setting the cleanup interval
Monitor your build times after making changes to ensure optimal performance
Recommended Settings:
For frequently building teams: 2-3 days
For occasional builds: 1-2 days
For storage cost optimization: 1 day