CentOS

Docker は CentOS 7.X で動作します。Scientific Linux のような EL7 バイナリ互換のディストリビューションでもインストールは可能かもしれませんが、Docker はこれらのディストリビューションでテストしておらず、サポートも行いません。

このページでは Docker が管理しているパッケージとインストール手法を使ってインストールします。これらパッケ―ジを使い、Docker の最新リリースを入手します。もし CentOS が管理するパッケージを使いたい場合は、CentOS の Docker サポートに関する情報のドキュメントをお調べください。

動作条件

Docker は 64bit でインストールされた何らかの CentOS バージョンを必要とします。さらに、CentOS 7 で動作する kernel は少なくとも 3.10 以上が必要です。

現在のカーネル・バージョンを確認するには、ターミナルを開き、 uname -r を使ってカーネルのバージョンを確認します。

$ uname -r
3.10.0-229.el7.x86_64

最後に、システムを全て更新することをお勧めします。システムは潜在的なカーネルのバグを修正するために、全てパッチを当てるべきと考慮ください。報告されているカーネルのバグは、最新のカーネル・パッケージでは修正済みの場合があります。

Docker エンジンのインストール

Docker エンジンをインストールするには2つの方法があります。 yum パッケージ・マネージャを使い、直接自分でインストールできます。あるいは、 crulget.docker.com を使う方法があります。2つめの方法はインストール用のスクリプトを実行すると、 yum パッケージ・マネージャを通してセットアップします。

yum でインストール

  1. マシンに sudo あるいは root 特権のあるユーザでログインします。
  1. 既存の yum パッケージを更新します。
$ sudo yum update
  1. yum レポジトリを手動で追加します。
$ sudo tee /etc/yum.repos.d/docker.repo <<-EOF
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF
  1. Docker パッケージをインストールします。
$ sudo yum install docker-engine
  1. Docker デーモンを開始します。
$ sudo service docker start
  1. docker が正常にインストールされたか確認するため、コンテナでテスト用イメージを実行します。
$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
    latest: Pulling from hello-world
    a8219747be10: Pull complete
    91c95931e552: Already exists
    hello-world:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security.
    Digest: sha256:aa03e5d0d5553b4c3473e89c8619cf79df368babd1.7.1cf5daeb82aab55838d
    Status: Downloaded newer image for hello-world:latest
    Hello from Docker.
    This message shows that your installation appears to be working correctly.


    To generate this message, Docker took the following steps:
     1. The Docker client contacted the Docker daemon.
     2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
            (Assuming it was not already locally available.)
     3. The Docker daemon created a new container from that image which runs the
            executable that produces the output you are currently reading.
     4. The Docker daemon streamed that output to the Docker client, which sent it
            to your terminal.


    To try something more ambitious, you can run an Ubuntu container with:
     $ docker run -it ubuntu bash


    For more examples and ideas, visit:
     http://docs.docker.com/userguide/

スクリプトでインストール

同じ手順が CentOS Enterprise Linux の全てのバージョンで使えます。

  1. マシンに sudo あるいは root 特権のあるユーザでログインします。
  1. 既存の yum パッケージを更新します。
$ sudo yum update
  1. Docker インストール用スクリプトを実行します。
$ curl -sSL https://get.docker.com/ | sh
  1. Docker デーモンを起動します。
$ sudo service docker start
  1. docker が正常にインストールされたか確認するため、コンテナでテスト用イメージを実行します。
$ sudo docker run hello-world

docker グループの作成

docker デーモンは TCP ポートの替わりに Unix ソケットをバインドします。デフォルトでは、Unix ソケットは root ユーザによって所有されており、他のユーザは sudo でアクセスできます。このため、 docker デーモンは常に root ユーザとして実行されています。

docker コマンド利用時に sudo を使わないようにするには、 docker という名称のグループを作成し、そこにユーザを追加します。 docker デーモンが起動すると、docker グループの所有者により Unix ソケットの読み書きが可能になります。

警告

docker グループは root ユーザ相当です。システム上のセキュリティに対する影響の詳細は、 Docker デーモンが直面する攻撃 をご覧ください。

docker グループを作成し、ユーザを追加するには、

  1. Centos に sudo 特権のあるユーザでログインします。
  1. docker グループを作成し、ユーザを追加します。
$ sudo usermod -aG docker ubuntu
  1. ログアウトしてから、再度ログインします。

対象ユーザが正しい権限を持つようにするためです。

  1. sudo を使わずに docker が実行できることを確認します。
$ docker run hello-world

ブート時の Docker 開始設定

Docker をブート時に起動するようにするには、次のように実行します。

$ sudo chkconfig docker on

HTTP プロキシの追加が必要な場合、Docker のランタイム・ファイルを異なったディレクトリやパーティションに置いてください。あるいは別のカスタマイズ方法として、Systemd の記事 Systemd Docker デーモン・オプションのカスタマイズ から、どのように設定するかをご覧ください。

アンインストール

Docker ソフトウェアを yum でアンインストール可能です。

  1. インストールしたパッケージの一覧を表示します。
$ yum list installed | grep docker
yum list installed | grep docker
docker-engine.x86_64                1.7.1-0.1.el7@/docker-engine-1.7.1-0.1.el7.x86_64
  1. パッケージを削除します。
$ sudo yum -y remove docker-engine.x86_64

上記のコマンドは、イメージ、コンテナ、ボリュームやホスト上の設定ファイルを削除しません。

  1. イメージ、コンテナ、ボリュームを削除するには次のコマンドを実行します。
$ rm -rf /var/lib/docker
  1. ユーザが作成した設定ファイルを探して削除します。