Docker Layer Caching (DLC)

Learn how DLC can reduce build times on CircleCI, limitations, and best practices.


Welcome to the Docker Layer Caching (DLC) Course

In this course, we cover concepts regarding DLC. This training may be particularly useful for CircleCI customers who would like to minimize their use of DLC for building docker images.  

Who should take this course?

This course is designed for CircleCI developers using the cloud hosted solution. You should be familiar with managing source code in a VCS such as GitHub or Bitbucket; have a working knowledge of editing YAML files, and experience using command line utilities to automate builds and deploys for the technology stack at your organization. This course is intentionally code-agnostic, with an assumption that you have a clear understanding of the commands appropriate for your tooling, that you would use to build, test, and deploy projects. 

Duration: ~10 minutes




How Docker Layer Caching Works

Course SCORM:

Concepts covered in this lesson include:

  • Layering of a Docker file
  • Where new builds begin
  • Review of a Docker layer caching demo


Docker Layer Caching in CircleCI


Course SCORM:

in this lesson, you will learn about:

  • Enabling Docker layer caching
  • Attaching a DLC volume to an executor
  • Attaching a DLC volume to multiple executors
  • Limitations of Docker layer caching


Caching from a Remote Registry

Course SCORM:

In this lesson, you will learn about:

  • Creating a cache
  • Saving cache to remote registry
  • Pulling cache from registry


Docker Layer Caching Best Practices

Docker Layer Caching Best Practices

Structuring Docker Layers

As we have already discussed, all steps following a change in your Docker file will need to be rebuilt and can not be pulled from a cache. In this example, the step containing your code is the step most likely to change. In this case “COPY .”.  This means each time this file is built, that layer, and every layer below it, must be rebuilt. The more layers that need rebuilt, the longer your build takes and the more it costs. The code dependencies and requirements will not change nearly as often.


This means that it’s important to structure your Docker build in a way that takes the most advantage of your cache. In this example, we have moved the layer most likely to change farther down in the Docker file, increasing the number of layers that can be pulled from a cache. This reduces the build time and saves money.


General Resources:

Was this article helpful?
0 out of 0 found this helpful



Article is closed for comments.