Sign inSign up free

848. Stop Re-Downloading Packages on Every Build

hard 40 XP ~12 minHands-on lab

Labs have no container engine, so nothing is built: your files are checked by reading them.

requirements.txt of audit-log changes almost daily, and every time the CI builder downloads all 400 MB of wheels again. The same happens to the apt packages.

Task

Change /home/student/projects/audit-log/Dockerfile to use BuildKit cache mounts (the files stay out of the image, but survive between builds on the same builder):

  • the first line declares the frontend syntax # syntax=docker/dockerfile:1,
  • the pip install RUN mounts a cache at /root/.cache/pip and no longer uses --no-cache-dir,
  • the apt RUN mounts caches at /var/cache/apt and /var/lib/apt, both with sharing=locked, and no longer deletes /var/lib/apt/lists,
  • the Debian image's automatic cache cleanup is disabled before apt runs: delete /etc/apt/apt.conf.d/docker-clean,
  • packages, COPY lines and CMD stay as they are.

About this machine

Ubuntu 24.04 with no internet access. You are student with passwordless sudo. The grader checks the final state of the machine, not the commands you typed. Values like names and ports are generated for you.

Part of Docker Fundamentals. Next step: Publishing Ports

Teaching or writing about this? Embed this lab on your page

TerminalNot started

Your machine is ready to start

A fresh, isolated Ubuntu machine boots in a few seconds with the task already set up.

No account needed: 3 of 3 free tries left. Guest machines last 30 minutes.