LoginSignup
3
11

More than 5 years have passed since last update.

Ubuntu16.04へのDocker CEインストール手順

Last updated at Posted at 2017-07-14

はじめに

今更感がハンパなさすぎますが、UbuntuにDockerをインストールしてみたのでその手順をメモ程度に記しておきます。
公式のインストール手順と基本変わらないです。。。

Dockerについて

Dockerの現在のバージョンは17.06となっており(2017/07/13現在)
サポートされているUbuntuのバージョンは以下のとおりです。

  • Zesty 17.04
  • Yakkety 16.10
  • Xenial 16.04 (LTS)
  • Trusty 14.04 (LTS)

今回自分はXenial 16.04(LTS)でインストールしました。

また、Dockerには商用のDockerEE(Enterprise Edition)と無料版のDockerCE(Community Edition)の2種類があり今回自分がインストールしたのはCEの方になります。

インストール前準備

Dockerをインストールする前にいくつか作業があります。

旧バージョンの削除

旧バージョンのDockerがインストール済みの方はそちらを削除してください。
$ sudo apt-get remove docker docker-engine docker.io

Trusty 14.04 (LTS)の推奨パッケージ

Ubuntu14.04の場合、DockerがauFSというファイルシステムを使用できるように以下のパッケージをインストールすることが推奨されているようです。

$ sudo apt-get update

$ sudo apt-get install \
    linux-image-extra-$(uname -r) \
    linux-image-extra-virtual

16.04以降のバージョンでは、auFSの代わりであるOverlayFSのサポートがカーネルに含まれているため上記パッケージのインストールは不要です。

Dockerのインストール

Dockerをインストールするには以下の2つの方法があります。

  • Dockerのリポジトリを設定してインストールする
  • debパッケージをダウンロードしてそれをインストールする

インストールやアップグレードの作業が容易なことから、リポジトリを設定してインストールする方法が推奨されているようです。
自分も今回はリポジトリを設定する方法でインストールしたので、そちらの方法を説明していきます。

リポジトリの設定

1. aptパッケージの更新

まずはaptのパッケージを更新します。
$ sudo apt-get update

2. HTTPS経由でリポジトリを使用するためのパッケージのインストール

以下のコマンドで必要なパッケージをインストールしてください。

$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common

3. DockerのGPGキーの追加

GPGキーとはGNU Privacy Guardという暗号化ソフトで生成されるキーのことです。
Linuxでは、apt-getやyumなどでインストールしたパッケージが正しい配布先のものかどうかのチェックなどに使用されています。
以下のコマンドで公式のGPGキーを追加してください。
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
その後、
$ sudo apt-key fingerprint 0EBFCD88
を実行してGPGキーのfingerprint(電子指紋)が
9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
であることを確認します。
出力は以下のようになるはずです。

pub   4096R/0EBFCD88 2017-02-22
      Key fingerprint = 9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid                  Docker Release (CE deb) <docker@docker.com>
sub   4096R/F273FCD8 2017-02-22

4. リポジトリを設定する

$ sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

Dockerのインストール

1. aptのアップデート

アップデートしときましょう
$ sudo apt-get update

2. Docker-CEのインストール

aptを使ってDockerをインストールします。
$ sudo apt-get install docker-ce

3. Dockerの実行

以下のコマンドでDockerを実行します
$ sudo docker run hello-world
以下のようなメッセージが表示されれば正常にインストールされています。

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.
 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

Share images, automate workflows, and more with a free Docker ID:
 https://cloud.docker.com/

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

最後に

公式のインストール手順で全く問題なかったので、ただの写経になってしまった、、、
様々な場面で使えるDockerですので、これからどんどん活用していこうと思います:))

3
11
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
3
11