LoginSignup
1
0

More than 1 year has passed since last update.

dockerコンテナにgitの最新バージョンを入れる

Last updated at Posted at 2023-02-15

コンテナ内にあるgitが少し古い

 今回、pythonを動かそうと公式からイメージを取ってきたところgitのバージョンが少し古くなってました。古くても特に問題はなさそうなんですが、最新バージョンを入れる方法を知っておこうと調べました。初心者の備忘録なので間違いがあればご指摘お願いします。

Dockerfileへの記述

FROM python:3

# インストール前に下準備
# updateでインストールできるパッケージリストの更新、upgradeでインストール済みパッケージの更新
RUN apt-get update -y \
    && apt-get upgrade -y

# 必要なライブラリをインストール
RUN apt-get install -y gettext \
    libcurl4-gnutls-dev \
    libexpat1-dev \
    libghc-zlib-dev \
    libssl-dev \
    make \
    wget
    
# Gitをソースからコンパイルしてインストール
RUN wget https://github.com/git/git/archive/v2.30.0.tar.gz \
    && tar -xzf v2.30.0.tar.gz \
    && cd git-* \
    && make prefix=/usr/local all \
    && make prefix=/usr/local install

# 最後に不必要なパッケージの削除
RUN apt-get autoremove -y

ちなみに

 シェルスクリプトにbashを使用しているのですが、gitコマンドのtab補完機能を有効化するために必要なgit-completion.bashは以下にありました。初心者には特にありがたい機能です。
 /git-2.38.1/contrib/completion/git-completion.bash

参考

1
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
1
0