LoginSignup
181
175

More than 5 years have passed since last update.

[Docker] ubuntu 14.04/16.04にDockerをインストール

Last updated at Posted at 2015-05-30

ubuntuのaptで取得できるdockerがv1.0.1と古すぎたので、(2015/5/30時点の)最新の方法を調査した。
ググって出てくる情報は1.0.1だとほとんど動かなかったため、お試しでも最新を使ったほうが良いと思われる

2017/01/05 追記:
内容が古くなっていたので更新しました。
初稿の2015/5/30時点では wget -qO- https://get.docker.com/ | sh でインストールできたんですが、今は公式ドキュメントからその記述が無くなっている様子なので、公式ドキュメントを正として再検証しました。(https://get.docker.com/が消えているわけではなく、実行自体はできるようですが現在どういう状態かは不明)

このドキュメントも古くなっていくため、基本的に以下の公式ドキュメントを正として下さい。
Install Docker on Ubuntu - Docker

2017/06/23 追記:
前回の記事アップデート後からDockerはしばらく触ってなかったんですが、どうも docker-cedocker-ee というパッケージに分かれて、インストール方法も変わった様子です。
Dockerが商用版Dockerとして「Docker Enterprise Edition」発表、認証済みイメージやプラグインなど提供。無償版は「Community Edition」に - Publickey

再検証後本記事もアップデート予定ですが、それまでは本記事は参考程度にして以下の公式を参照して下さい。
Get Docker for Ubuntu | Docker Documentation

インストール

インストール手順

必要パッケージのインストール
$ sudo apt-get update
$ sudo apt-get install apt-transport-https ca-certificates
GPG鍵の取得
$ sudo apt-key adv \
               --keyserver hkp://ha.pool.sks-keyservers.net:80 \
               --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

source.list.d/docker.list は、ディストリビューションのバージョンに合わせて変更する。

source.listの更新
# 14.04
$ echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" | sudo tee /etc/apt/sources.list.d/docker.list
# 16.04
$ echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" | sudo tee /etc/apt/sources.list.d/docker.list

ubuntuの場合はさらに依存パッケージをインストールする。
https://docs.docker.com/engine/installation/linux/ubuntulinux/#/prerequisites-by-ubuntu-version

依存パッケージのインストール
$ sudo apt-get update
$ sudo apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual

docker-engine のインストール
https://docs.docker.com/engine/installation/linux/ubuntulinux/#/install-the-latest-version

docker-engineのインストール
$ sudo apt-get update
$ sudo apt-get install docker-engine

動作検証

※プロキシ環境下の場合はおそらく失敗するので先にプロキシ設定を行って下さい。

動作検証として、hello-worldイメージを実行してみた例です。

$ sudo service docker start
$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world

c04b14da8d14: Pull complete
Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9
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.
 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 Hub account:
 https://hub.docker.com

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

プロキシ設定

外部ネットワーク接続時にプロキシの設定が必要な場合は以下のようにします。

proxy設定の変更
$ sudo mkdir /etc/systemd/system/docker.service.d
$ sudo touch /etc/systemd/system/docker.service.d/http-proxy.conf
$ sudo vi /etc/systemd/system/docker.service.d/http-proxy.conf
/etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://proxy.example.com:80/" "NO_PROXY=localhost,127.0.0.1"

一応補足ですが、http://proxy.example.com:80/ となっている箇所はお使いの環境に合わせて変更してください。

設定の反映
$ sudo systemctl daemon-reload
$ systemctl show --property=Environment docker
Environment=HTTP_PROXY=http://proxy.example.com:80/ NO_PROXY=localhost,127.0.0.1
$ sudo systemctl restart docker

ユーザーを docker グループに追加

dockerのソケットファイルにアクセスするのに rootかdocker groupである必要があるので、
以下のようにしてグループに追加する(別に毎回sudoつけるならそれでもよい)。

$ sudo usermod -aG docker $USER

# reboot か再ログインが必要、再ログインなら以下のようにする
# http://askubuntu.com/questions/69221/adding-user-to-a-group-why-had-to-reboot
# (20150531追記)
# screenやtmuxが立ち上がっているとうまくいかない? その場合はrebootしてください
$ su - $USER

自動起動設定

ubuntu16.04
$ sudo systemctl enable docker

ubuntu14.04はupstartで、勝手に自動起動設定がされるらしい。

アップデート

アップデートの際には以下のようにする

$ sudo apt-get update
$ sudo apt-get upgrade docker-engine

その他Docker関連資料

参考

docker公式(ubuntu用インストール解説)
アプリ開発者もインフラ管理者も知っておきたいDockerの基礎知識
ついに1.0がリリース! Dockerのインストールと主なコマンドの使い方 (1/3)
Dockerfileとdocker buildコマンドでDockerイメージの作成 (1/2)

181
175
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
181
175