0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Docker】aptパッケージをキャッシュする方法

Last updated at Posted at 2024-06-01

Dockerfileに以下のように記述するとaptパッケージをキャッシュできます。

# syntax=docker/dockerfile:1

# ...

# apt-get install実行後に/var/cache/apt内のdebファイルが削除されないようにする
RUN rm -f /etc/apt/apt.conf.d/docker-clean
# aptパッケージをキャッシュする
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
  --mount=type=cache,target=/var/lib/apt,sharing=locked \
  apt-get update && apt-get --no-install-recommends install -y gcc

apt-getを使用する場合にはecho 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cacheは不要です。

参考

  • rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache について

  • --mount=type=cacheについて

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?