公式の情報など
公式ドキュメントがありますので参照してください。
docker公式のインストールガイド(英語)
左側のメニュー→Docker Engine →install→各OSの説明 Mac、WindowはもちろんLinuxは主要ディストリビューションのほとんどのインストール方法解説を網羅しています。
docker日本語マニュアルプロジェクト
左側のメニュー→Docker Engine →インストールこちらは有志の方が英語ドキュメントを日本語訳してくれているプロジェクトです。こちらもMac、Window、Linuxの主要ディストリビューションのインストール方法解説があります。
インストールの手順
手順1 カーネルバージョンの確認
DockerEngineはカーネルバージョンが3.10以上で64bitじゃないと動かないそうです(64bitでも5や6はカーネルバージョンが2.6.32-573以下なのでダメです)。
カーネルバージョンを確認するには以下のコマンドを使います。
$ uname -r
3.10.0-327.10.1.el7.x86_64
手順2 パッケージのアップデート
念の為パッケージのアップデートをしておきます。
$ sudo yum update
手順3 リポジトリの追加orインストールスクリプトの実行
公式にはインストール方法が2つ紹介されています。リポジトリを追加してyum
でインストールする方法とインストールスクリプトを使う方法です。
インストールスクリプトを使う場合
かーるちゃんでスクリプトを取り寄せ実行します。
$ curl -fsSL https://get.docker.com/ | sh
こちらの場合はインストールまでスクリプトが手続きしてくれるので、次の手順4は行わなくて大丈夫です。
リポジトリを追加する場合
tee
コマンドでリポジトリを追加します。手動でファイルを作っても問題ないです。
$ sudo tee /etc/yum.repos.d/docker.repo <<-'EOF'
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF
手順4 パッケージインストール
docker-engine
パッケージをインストールします。
インストールスクリプトを使った場合はこの手順は必要ないです。
$ sudo yum install docker-engine
手順5 起動
Dockerデーモンを起動します。
$ sudo service docker start
手順6 テスト
正常に動くかテスト用のコンテナを起動して確認します。以下のような表示が出たら成功です。
$ 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/
手順7 自動起動の設定
DockerEngineの自動起動設定を行っておいたほうが良いかと思います。
公式ではchkconfig
を使った方法が紹介されています。
$ sudo chkconfig docker on
CentOS7からはsystemdで管理されているので、
$sudo systemctl enable docker.service
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
としても自動起動の設定ができます。
手順8 dockerグループへの追加
Dockerコマンドの実行はsudo
が必要になります。dockerグループに追加することでsudo
を打たずに実行できるようになります。
グループの確認
おそらくインストール時にdockerグループができているかと思いますが、ない場合は作ってください。
グループへの追加
Dockerで作業を行うsudo
権限もったユーザでログインします。
グループに追加します。G
オプションを忘れるとグループ情報が上書きされてしまうので注意です。
$ sudo usermod -aG docker your_username
実行確認
公式ではログアウトして再度ログインするとありますが、もし可能ならマシンの再起動をしたほうが、一発で権限が戻りますのでおすすめです。
最後にsudo無
しでdocker
コマンドを実行して確認してください。
$ docker run hello-world
後記
海外ではCentoOSよりUbuntuがサーバとして使われているとか聞きますが、日本ではCentOS使う場合って多いみたいですよね。
Dockerのようなコンテナ仮想がもっと普及したら、コンテナ用の超軽量OSとか出てくるんでしょうか?