ubuntu 16.04でdockerを使う
前回、こんな記事をかきました。
kei0425tan.hatenablog.com
そういえば、ubuntuでのdocker最新版の使い方を書いていなかったのでメモしておきます。
パッケージを使う
これだけです。(最新版を使う場合にはインストールしないでください)
$ sudo apt-get docker.io
(なお、dockerのみの場合は、KDE3/GNOME2 docklet アプリケーション用システムトレイになってしまいます。)
しかし、問題がありまして、バージョンが結構古いです。
ubuntu 16.04でインストールされるバージョンは以下です。
Version: 1.12.6-0ubuntu1~16.04.1
dockerは結構バージョンアップが激しく、機能もかなり変わっているため、なるべく最新版を使いたいところです。
最新版のインストール方法
公式サイトにインストール方法はのっています。
docs.docker.com
まあ、英語なんですが。
なので、日本語で書いておきます。
必要なパッケージの追加
$ sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ software-properties-common
dockerの公式GPGキーを追加
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
fingerprintの確認
こちらは念のため。必須ではありません。
$ 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のリポジトリを追加
armhf(Raspberry Piとか)の場合はリポジトリが異なるので注意しましょう。
$ sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable"
dockerのインストール
リポジトリを追加したので、updateをしましょう。
$ sudo apt-get update
dockerをインストールしましょう。
$ sudo apt-get install docker-ce
後ろのceはコミュニティエディション(Community Edition)の略です。
お仕事向けの場合は、ee(Docker Enterprise Edition)になります。手順も多少異なるので気を付けてください。
インストールすると、デーモンも自動的に起動します。
確認
$ 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が利用できますが、いろいろ設定しておいたほうが便利に利用できるかと思います。
docker-composeのインストール
dockerを生で使うと起動時のオプションとかの管理が大変です。
コンテナの起動順とかコンテナ同士の連携とか、、、、
そういったものを設定ファイルに記述して簡単に扱うことができるツールがdocker-composeになります。
グループ設定
ユーザへのdockerグループの追加
$ sudo usermod -aG docker $USER
これにより、dockerをsudoなしで動かすことができます。
以上、お疲れ様でした。