Shared caches
Share download and build caches between all containers, so each new container doesn’t download the same tools, modules and packages again. This guide builds on Project toolchains and caches mise downloads, Go modules and builds, npm packages and Playwright browsers.
Set up
Use the files in examples/guides/caches:
# yaml-language-server: $schema=https://isodev.dyszkiewicz.me/config.schema.json
# Download and build caches shared by all containers, on top of the mise guide.
# Each cache is a named Docker volume, which Docker creates on first use and
# Isodev never removes.
image: isodev-caches:latest
build:
context: image
environment:
# Go keeps modules in ~/go/pkg/mod by default; use the shared cache instead.
GOMODCACHE: /root/.cache/go-mod
volumes:
# Tool downloads made by mise.
- type: volume
source: isodev-cache-mise
target: /root/.cache/mise
# Go modules and build cache.
- type: volume
source: isodev-cache-go-mod
target: /root/.cache/go-mod
- type: volume
source: isodev-cache-go-build
target: /root/.cache/go-build
# npm package cache.
- type: volume
source: isodev-cache-npm
target: /root/.npm/_cacache
# Playwright browser downloads.
- type: volume
source: isodev-cache-ms-playwright
target: /root/.cache/ms-playwright
lifecycle:
on_create:
scripts:
- file: hooks/mise.shFROM ubuntu:24.04
ARG DEBIAN_FRONTEND=noninteractive
# mise installs tools to ~/.local/share/mise and puts them on PATH through its
# shims. /usr/local/bin comes first, so files mounted there win.
ENV PATH=/root/.local/bin:/usr/local/sbin:/usr/local/bin:/root/.local/share/mise/shims:/usr/sbin:/usr/bin:/sbin:/bin
RUN apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates curl git \
&& rm -rf /var/lib/apt/lists/*
# mise, which installs the tools.
RUN curl -fsSL https://mise.run | MISE_INSTALL_PATH=/usr/local/bin/mise sh#!/bin/sh
# Runs once in each new container, in the workspace.
set -eu
# Install the project's tools when it has a mise or asdf configuration.
for config in mise.toml .mise.toml .tool-versions .config/mise/config.toml; do
if [ -f "$config" ]; then
mise trust
mise install
break
fi
doneEach cache is a named Docker volume, which Docker creates the first time a container uses it. Isodev never removes named volumes, so the caches outlive every container. They live on Docker’s own disk, which on macOS is faster than sharing a directory from the Mac.
Go, npm and Playwright support several containers using their caches at the same time. mise only keeps downloaded archives in its cache; the tools it installs stay private to each container.
To cache other tools, add a volume at the path where the tool keeps its cache, for example /root/.cache/pip for pip, or set the tool’s cache variable in environment.
Use it
isodev up --recreate
docker system df -v | grep isodev-cacheTrade-offs
- Containers share what they download. A container can read and change cache entries that other containers use.
- The caches grow. Isodev doesn’t clean them. To empty one, remove its volume while no container uses it, for example
docker volume rm isodev-cache-go-mod; Docker creates it again, empty, for the next container.