0
0

More than 1 year has passed since last update.

【Docker】コンテナに最新のGitをインストールする方法

Posted at

最新のGitをインストールする

Debianの場合には最新版のGitをインストールするためにはソースからインストールする必要があります。
そのためDockerfileに以下のように記述します。

Dockerfile
# syntax=docker/dockerfile:1

...

ARG GIT_VERSION=2.38.0

RUN <<-EOF
	set -eu
  # 必要なパッケージをインストール
	apt-get update -qq
	apt-get install -qy libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev
	cd /usr/local/src
  # Gitのソースコードをリポジトリからダウンロード
	wget https://github.com/git/git/archive/refs/tags/v${GIT_VERSION}.tar.gz
  # ビルド
	tar -xzf v${GIT_VERSION}.tar.gz
	cd git-${GIT_VERSION}
	make prefix=/usr/local all -j "$(nproc)"
	make prefix=/usr/local install
EOF

...

コンテナ内でgit --versionを実行して指定したバージョンになっているか確認します。

$ git --version
git version 2.38.0
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