LoginSignup
1
1

More than 5 years have passed since last update.

EC2のUbuntu14.04にDocker-CEとdocker-composeをインストール

Posted at

複数のインストール方法がある

Install using the repository

この記事ではapt-getを使うやり方を紹介

挫折した人は別の方法でも

Install from a package

パッケージをダウンロードして、そこからインストール

Install using the convenience script

便利スクリプトをダウンロードしてきてそれを起動するだけの簡単インストール(これやればよかった、先に書いてよね)

Dockerインストール方法(Install using the repository)

AWSのEC2でUbuntuインスタンスを作る

EC2の使い方は割愛。
使うマシンイメージは「Ubuntu Server 14.04 LTS (HVM), SSD Volume Type - ami-15e58f73」
クイックスタートの下の方にある、無料利用枠のUbuntu。

なんとなく最低限gitをインストール

$ sudo apt-get install git

Dockerをインストールする作業

此処から先は以下のURLの通りにやっていく
https://docs.docker.com/install/linux/docker-ce/ubuntu/#install-docker-ce

Dockerを入れる前の事前準備

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

Dockerをインストール(リポジトリから)

$ sudo apt-get update
$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

OK

$ sudo apt-key fingerprint 0EBFCD88

〜〜〜〜〜〜〜〜〜〜〜〜
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
(最後が「9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88」なら良いよ、みたいなことをDocker公式様が言っている)

サーバーのアーキテクチャを確認

(やんなくてもいいよ)
$ arch

x86_64

$ dpkg --print-architecture

amd64

AWSのUbuntuインスタンス使ってるなら同じだと思うので、確認しなくても・・・・いいかな。

サーバーのアーキテクチャに合わせたコマンドを実行

Docker公式様のインストールガイドだとタブになっててアーキテクチャ選ぶ。
今回は「x86_64 / amd64」なので以下のコマンドを実行

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

テスト

$ sudo docker run hello-world

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest: sha256:083de497cff944f969d8499ab94f07134c50bcf5e6b9559b27182d3fa80ce3f7
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.
(なんかごちゃごちゃ言われるけどエラーは出て無ければ大丈夫)

(オプション)特定のDockerがインストールしたい場合の話

# インストールできるバージョンを確認
$ apt-cache madison docker-ce

# 好きなバージョンをインストール(できるらしい)
$ sudo apt-get install docker-ce=<VERSION>

ついでに絶対欲しいDocker-Composeもインストール

$ sudo curl -L https://github.com/docker/compose/releases/download/1.19.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   617    0   617    0     0    949      0 --:--:-- --:--:-- --:--:--   950
100 8288k  100 8288k    0     0  1453k      0  0:00:05  0:00:05 --:--:-- 1818k

$ sudo chmod +x /usr/local/bin/docker-compose
$ docker-compose --version

docker-compose version 1.19.0, build 9e633ef

ユーザー設定とか

Post-installation steps for Linux

$sudo groupadd docker

groupadd: group 'docker' already exists
(やれって書いてあるからやったのに、何故かすでにあるっていう・・・ね)

$ sudo usermod -aG docker $USER

試してみる

$ docker run hello-world

docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.35/containers/create: dial unix /var/run/docker.sock: connect: permission denied.
See 'docker run --help'.

だめじゃねーか!!!!!怒

グループに追加されてない?

$grep docker /etc/group

docker:x:999:(ユーザー名)

あるなぁ。

/var/run/docker.sockの権限?

$ ls -la /var/run/docker.sock
srw-rw---- 1 root docker 0 Mar  2 10:07 /var/run/docker.sock

dockerグループになってるなぁ。

Dockerが動いている

$ sudo status docker

docker start/running, process 10568

試しに再起動してみる

(結論)一度、SSHをつなぎ直す

$ exit

$ ssh (サーバー)

$ docker run hello-world

これでいけました。

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