我正在使用 Github Actions 构建 Docker 镜像。我缓存了 Docker 层(这很有效),但有时层不会被重用(不确定原因!我遵循 最佳实践,但忽略了那个问题),我使用备用的 pip 缓存来加速构建。
Dockerfile 很简单:
我正在使用
Github actions缓存(我想将其挂载在构建容器上):
我可以为您提供翻译帮助。以下是需要翻译的内容:
Dockerfile 很简单:
# syntax=docker/dockerfile:1.2
FROM python:3.10-slim
RUN python -m pip install --upgrade pip && pip cache dir
COPY requirements.txt ./
RUN --mount=type=cache,target=/root/.cache/pip/ pip install -r requirements.txt
我正在使用
--mount
标志来自语法1.2,它“允许构建容器缓存编译器和软件包管理器的目录”。Github actions缓存(我想将其挂载在构建容器上):
- name: Cache pip
uses: actions/cache@v3
with:
path: /root/.cache/pip
key: pip-{{ hashFiles('requirements*.txt') }}
和 Docker 构建
- name: Build and push
uses: docker/build-push-action@v2
with:
cache-from: type=gha
cache-to: type=gha,mode=max
我可以为您提供翻译帮助。以下是需要翻译的内容:
如何将pip缓存挂载到docker builder容器中?
目前,在dockerfile中使用此命令时,缓存为空:
RUN --mount=type=cache,target=/root/.cache/pip/ pip cache info && ls /root/.cache/pip
输出:
19 RUN --mount=type=cache,target=/root/.cache/pip/ pip cache info && ls /root/.cache/pip
#19 0.387 Package index page cache location: /root/.cache/pip/http
#19 0.387 Package index page cache size: 0 bytes
#19 0.387 Number of HTTP files: 0
#19 0.387 Wheels location: /root/.cache/pip/wheels
#19 0.387 Wheels size: 0 bytes
#19 0.387 Number of wheels: 0
#19 DONE 0.4s